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

MongoDB 3.6: implement the new wire protocol #61

Merged
merged 9 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from 7 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
24 changes: 10 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ language: go

go_import_path: github.com/globalsign/mgo

go:
- 1.8.x
- 1.9.x

env:
global:
- BUCKET=https://s3.eu-west-2.amazonaws.com/globalsign-mgo
- FASTDL=https://fastdl.mongodb.org/linux
matrix:
- GO=1.7 MONGODB=x86_64-2.6.11
- GO=1.8.x MONGODB=x86_64-2.6.11
- GO=1.7 MONGODB=x86_64-3.0.9
- GO=1.8.x MONGODB=x86_64-3.0.9
- GO=1.7 MONGODB=x86_64-3.2.3-nojournal
- GO=1.8.x MONGODB=x86_64-3.2.3-nojournal
- GO=1.7 MONGODB=x86_64-3.2.12
- GO=1.8.x MONGODB=x86_64-3.2.12
- GO=1.7 MONGODB=x86_64-3.2.16
- GO=1.8.x MONGODB=x86_64-3.2.16
- GO=1.7 MONGODB=x86_64-3.4.8
- GO=1.8.x MONGODB=x86_64-3.4.8
- MONGODB=x86_64-ubuntu1404-3.0.15
- MONGODB=x86_64-ubuntu1404-3.2.17
- MONGODB=x86_64-ubuntu1404-3.4.10
- MONGODB=x86_64-ubuntu1404-3.6.0-rc3

install:
- eval "$(gimme $GO)"

- wget $BUCKET/mongodb-linux-$MONGODB.tgz
- wget $FASTDL/mongodb-linux-$MONGODB.tgz
- tar xzvf mongodb-linux-$MONGODB.tgz
- export PATH=$PWD/mongodb-linux-$MONGODB/bin:$PATH

Expand Down
57 changes: 27 additions & 30 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ func (socket *mongoSocket) Login(cred Credential) error {
return nil
}
}
if socket.dropLogout(cred) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an weird idea originally? Nice fix

debugf("Socket %p to %s: login: db=%q user=%q (cached)", socket, socket.addr, cred.Source, cred.Username)
socket.creds = append(socket.creds, cred)
socket.Unlock()
return nil
}
socket.Unlock()

debugf("Socket %p to %s: login: db=%q user=%q", socket, socket.addr, cred.Source, cred.Username)
Expand Down Expand Up @@ -412,36 +406,50 @@ func (socket *mongoSocket) Logout(db string) {
cred, found := socket.dropAuth(db)
if found {
debugf("Socket %p to %s: logout: db=%q (flagged)", socket, socket.addr, db)
socket.logout = append(socket.logout, cred)
socket.Unlock()
err := socket.flushLogout(cred)
if err != nil {
debugf("fail to logout for cred %v; error: %v", cred, err)
}
} else {
socket.Unlock()
}
socket.Unlock()
}

func (socket *mongoSocket) LogoutAll() {
socket.Lock()
if l := len(socket.creds); l > 0 {
debugf("Socket %p to %s: logout all (flagged %d)", socket, socket.addr, l)
socket.logout = append(socket.logout, socket.creds...)
credCopy := make([]Credential, l)
copy(credCopy, socket.creds)
socket.creds = socket.creds[0:0]
socket.Unlock()
debugf("Socket %p to %s: logout all (flagged %d)", socket, socket.addr, l)
err := socket.flushLogout(credCopy...)
if err != nil {
debugf("fail to logout for cred %v, error: %v", credCopy, err)
}
} else {
socket.Unlock()
}
socket.Unlock()
}

func (socket *mongoSocket) flushLogout() (ops []interface{}) {
socket.Lock()
if l := len(socket.logout); l > 0 {
func (socket *mongoSocket) flushLogout(cred ...Credential) error {
if l := len(cred); l > 0 {
debugf("Socket %p to %s: logout all (flushing %d)", socket, socket.addr, l)
ops := make([]interface{}, l)
for i := 0; i != l; i++ {
op := queryOp{}
op.query = &logoutCmd{1}
op.collection = socket.logout[i].Source + ".$cmd"
op.collection = cred[i].Source + ".$cmd"
op.limit = -1
ops = append(ops, &op)
ops[i] = &op
}
err := socket.Query(ops...)
if err != nil {
return fmt.Errorf("fail to logout: %v", err)
}
socket.logout = socket.logout[0:0]
}
socket.Unlock()
return
return nil
}

func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
Expand All @@ -454,14 +462,3 @@ func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
}
return cred, false
}

func (socket *mongoSocket) dropLogout(cred Credential) (found bool) {
for i, sockCred := range socket.logout {
if sockCred == cred {
copy(socket.logout[i:], socket.logout[i+1:])
socket.logout = socket.logout[:len(socket.logout)-1]
return true
}
}
return false
}
Loading