[GODRIVER-1652] Primary StepDown Created: 15/Jun/20 Updated: 27/Oct/23 Resolved: 18/Jun/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Administrative Commands |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Fulton Byrne | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MongoDB 3.4 |
||
| Description |
|
Trying to run replica set step down command on version 3.4 MongoDB and keep getting the following error:
Here's the code:
I see these "unable to decode message length" errors quite a bit. Is there a good way to debug them?
I'm trying to follow what's in the tests, but seems I'm doing something unfortunate:
|
| Comments |
| Comment by Divjot Arora (Inactive) [ 18/Jun/20 ] |
|
Hi fbyrne, By default, the Go Driver will discover all nodes in a replica set, even if you only provide one of them in the URI. This default read preference is already primary, so all read operations including those sent by RunCommand will be sent to the primary. You can use the read preference to change this and send things to secondary servers if needed. I'm going to close out this issue as "Works as Designed" but feel free to leave a comment if you have any other questions and we can re-open if needed. – Divjot |
| Comment by Fulton Byrne [ 18/Jun/20 ] |
|
Divjot thank you so much for the thorough answer. This is amazing! Thanks for the pointer for things to look forward to. One interesting thing I learned from that test was it seems you can use a replica set connection string, but set the read pref to primary to run commands on the primary?
Safe to close this issue. |
| Comment by Divjot Arora (Inactive) [ 16/Jun/20 ] |
|
Hi fbyrne, The driver reads the server response for an operation in two socket reads: one 4-byte read to get the message length and another (length-4) byte read to get the rest of the message. "Unable to decode message length" indicates that there was an error during the first read. "EOF" is the underlying error from Go's net library. In this case, it is the stringified version of the io.EOF error. Driver version 1.4.0 adds proper error unwrapping to our errors, so once that's released, you will be able to do errors.Is(io.EOF) to check for this specific error. You're correct that this is the same as the issue described in the StackOverflow post. If the net library returns EOF from a socket read, it indicates that the server closed the connection. This behavior changed in MongoDB version 4.2 because the server team made changes to avoid closing connections on primary stepdown. The Go Driver test you linked is expecting no error because it only runs on server versions 4.2 and higher (see https://github.com/mongodb/mongo-go-driver/blob/eb2c1c4315fb6cca5ed9189e5c56e258c05c7630/mongo/integration/primary_stepdown_test.go#L56). You can ignore this specific error by checking that it is of type mongo.CommandError and then doing CommandError.HasErrorLabel("NetworkError"). If this answers all of your questions, can we close out this ticket? – Divjot |
| Comment by Fulton Byrne [ 16/Jun/20 ] |
|
Most likely reason: https://stackoverflow.com/questions/44409747/error-while-trying-to-stepdown-mongodb-replica-set |
| Comment by Fulton Byrne [ 16/Jun/20 ] |
|
Turns out I'm using go.mongodb.org/mongo-driver v1.1.2 will try with later versions to get the new error message. |