Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket: only send client metadata once per socket #105

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,38 @@ func (cluster *mongoCluster) isMaster(socket *mongoSocket, result *isMasterResul
session := newSession(Monotonic, cluster, 10*time.Second)
session.setSocket(socket)

// provide some meta infos on the client,
// see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake
// for details
metaInfo := bson.M{"driver": bson.M{"name": "mgo", "version": "globalsign"},
"os": bson.M{"type": runtime.GOOS, "architecture": runtime.GOARCH}}
var cmd = bson.D{{Name: "isMaster", Value: 1}}

// Send client metadata to the server to identify this socket if this is
// the first isMaster call only.
//
// isMaster commands issued after the initial connection handshake MUST NOT contain handshake arguments
// https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake
//
socket.sendMeta.Do(func() {
var meta = bson.M{
"driver": bson.M{
"name": "mgo",
"version": "globalsign",
},
"os": bson.M{
"type": runtime.GOOS,
"architecture": runtime.GOARCH,
},
}

if cluster.appName != "" {
metaInfo["application"] = bson.M{"name": cluster.appName}
}
err := session.Run(bson.D{{Name: "isMaster", Value: 1}, {Name: "client", Value: metaInfo}}, result)
// Include the application name if set
if cluster.appName != "" {
meta["application"] = bson.M{"name": cluster.appName}
}

cmd = append(cmd, bson.DocElem{
Name: "client",
Value: meta,
})
})

err := session.Run(cmd, result)
session.Close()
return err
}
Expand Down
1 change: 1 addition & 0 deletions socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type mongoSocket struct {
dead error
serverInfo *mongoServerInfo
closeAfterIdle bool
sendMeta sync.Once
}

type queryOpFlags uint32
Expand Down