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

Recover from persistent "i/o timeout" or "Closed explicitly" pool errors #69

Merged
merged 1 commit into from
Dec 27, 2017
Merged
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
22 changes: 16 additions & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4800,13 +4800,13 @@ func (s *Session) acquireSocket(slaveOk bool) (*mongoSocket, error) {
s.m.RLock()
// If there is a slave socket reserved and its use is acceptable, take it as long
// as there isn't a master socket which would be preferred by the read preference mode.
if s.slaveSocket != nil && s.slaveOk && slaveOk && (s.masterSocket == nil || s.consistency != PrimaryPreferred && s.consistency != Monotonic) {
if s.slaveSocket != nil && s.slaveSocket.dead == nil && s.slaveOk && slaveOk && (s.masterSocket == nil || s.consistency != PrimaryPreferred && s.consistency != Monotonic) {
socket := s.slaveSocket
socket.Acquire()
s.m.RUnlock()
return socket, nil
}
if s.masterSocket != nil {
if s.masterSocket != nil && s.masterSocket.dead == nil {
socket := s.masterSocket
socket.Acquire()
s.m.RUnlock()
Expand All @@ -4820,12 +4820,20 @@ func (s *Session) acquireSocket(slaveOk bool) (*mongoSocket, error) {
defer s.m.Unlock()

if s.slaveSocket != nil && s.slaveOk && slaveOk && (s.masterSocket == nil || s.consistency != PrimaryPreferred && s.consistency != Monotonic) {
s.slaveSocket.Acquire()
return s.slaveSocket, nil
if s.slaveSocket.dead == nil {
s.slaveSocket.Acquire()
return s.slaveSocket, nil
} else {
s.unsetSocket()
}
}
if s.masterSocket != nil {
s.masterSocket.Acquire()
return s.masterSocket, nil
if s.masterSocket.dead == nil {
s.masterSocket.Acquire()
return s.masterSocket, nil
} else {
s.unsetSocket()
}
}

// Still not good. We need a new socket.
Expand Down Expand Up @@ -4876,9 +4884,11 @@ func (s *Session) setSocket(socket *mongoSocket) {
// unsetSocket releases any slave and/or master sockets reserved.
func (s *Session) unsetSocket() {
if s.masterSocket != nil {
debugf("unset master socket from session %p", s)
s.masterSocket.Release()
}
if s.slaveSocket != nil {
debugf("unset slave socket from session %p", s)
s.slaveSocket.Release()
}
s.masterSocket = nil
Expand Down