-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix "not master" error in mongo plugin #7743
Changes from 1 commit
8b0f654
10d84a1
95f52fd
a94e333
22c154d
4932579
016a8b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,10 +150,10 @@ func (m *MongoDB) CreateUser(ctx context.Context, statements dbplugin.Statements | |
} | ||
case strings.Contains(err.Error(), "not master"): | ||
// Close connection and reconnect if connected node is not primary. | ||
if m.mongoDBConnectionProducer.session != nil { | ||
m.mongoDBConnectionProducer.session.Close() | ||
if err := m.Close(); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to call Close There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does getConnection really close the session in this case though? What happens if the session is not nil already and the ping succeeds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can see getConnection calls Connection() in connection_producer.go which only closes the session if the session is not nil and the ping fails. The ping won't fail though, as the node is still up (it's just not the primary). I don't see a way to check whether it's master with the ping command. |
||
return "", "", errwrap.Wrapf("error closing EOF'd mongo connection: {{err}}", err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we set the session to nil afterwards? |
||
m.mongoDBConnectionProducer.session = nil; | ||
|
||
session, err := m.getConnection(ctx) | ||
if err != nil { | ||
return "", "", err | ||
|
@@ -214,10 +214,9 @@ func (m *MongoDB) SetCredentials(ctx context.Context, statements dbplugin.Statem | |
} | ||
case strings.Contains(err.Error(), "not master"): | ||
// Close connection and reconnect if connected node is not primary. | ||
if m.mongoDBConnectionProducer.session != nil { | ||
m.mongoDBConnectionProducer.session.Close() | ||
if err := m.Close(); err != nil { | ||
return "", "", errwrap.Wrapf("error closing EOF'd mongo connection: {{err}}", err) | ||
} | ||
m.mongoDBConnectionProducer.session = nil; | ||
|
||
session, err := m.getConnection(ctx) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locking inside Close() always produces a deadlock, as all of the calling functions (from mongodb.go) have locked the mutex already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close can be called externally which is why we need to lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I see two possibilities for dealing with that then.
Unlocking before calling it, and then locking again once done. (downside being that the lock needs to be acquired twice, and that another process can interfere inbetween the locking and unlocking)
Not calling it at all, and just closing the session by referencing the mongoDBConnectionProducer in mongodb.go. I had a commit where I did exactly this, and it worked ok.
What do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@calvn Close now locks again!