[CSHARP-2358] Sporadic exception opening connections: MongoDB.Driver.MongoAuthenticationException: Server sent an invalid nonce. Created: 17/Aug/18 Updated: 02/Jun/22 Resolved: 01/May/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Connectivity |
| Affects Version/s: | 2.1.1, 2.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Manuel Fontan Garcia (Inactive) | Assignee: | Unassigned |
| Resolution: | Cannot Reproduce | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
|
||
| Issue Links: |
|
||||||||||||
| Case: | (copied to CRM) | ||||||||||||
| Description |
|
MongoDB csharp driver is throwing an exception sporadically with authentication errors during scramsha1 authentication handshake due to a wrong nonce returned by the server. ScramSha1Authenticator.cs. The credentials are good since connections from the application are succeeding most of the time. Upgrading from 2.1.1.158 to 2.5.0.0 didn't fix the issue. I would like to understand why is the server retrieving a bad nonce and how to fix this issue. |
| Comments |
| Comment by Jeffrey Yemin [ 03/Sep/20 ] | |||||||||||||||
|
We are actively investigating the ongoing authentication failures in scope of | |||||||||||||||
| Comment by Mark Weaver [ 03/Sep/20 ] | |||||||||||||||
|
I can trivially reproduce this using the test code at: All on Windows 10 using mongo 4.4 community edition and the 2.11.1 c# driver. I have tried debugging the c# driver and it appears what is happening is that when two connections are opened simultaneously two separate nonces are generated (with two different ScramShaAuthenticator classes) and then subsequently ScramShaAuthenticator.Transition is called with the wrong response, e.g. I captured: ScramShaAuthenticator#1.rPrefix "MKS.RaW7GM5z.pJ-{s:Y" string ScramShaAuthenticator#2.Transition map["r"] = "MKS.RaW7GM5z.pJ-{s:Y9Rcih99HWu94edIYZpq157r7VX7TgCDR" string so the prefixes don't match and var r = map['r']; throws. Also looking with tcpdump I see that the server reply includes the nonce that the client is sending so that it appears that the issue is with the client rather than the server. I'm not sure where the mixing up is happening – some pointers would be helpful. | |||||||||||||||
| Comment by Gian Maria Ricci [ 24/Aug/20 ] | |||||||||||||||
|
I got the very same exception using 2.11 driver connecting only to mongodb 4.4, no error with mongo 4.0 | |||||||||||||||
| Comment by Jeffrey Yemin [ 14/Aug/20 ] | |||||||||||||||
|
We did find a bug, | |||||||||||||||
| Comment by Jeffrey Yemin [ 23/Aug/19 ] | |||||||||||||||
|
Closing as we have not been able to reproduce this issue. If anyone is impacted and can assist by providing Wireshark traces, we would be happy to re-open this. | |||||||||||||||
| Comment by Mathias Lorenzen [ 06/May/19 ] | |||||||||||||||
|
I forgot to mention I had also upgraded from MongoDB 3 to 4. Just now, I took the following steps:
This seems to reduce the amount of times the error is occuring. | |||||||||||||||
| Comment by Mathias Lorenzen [ 06/May/19 ] | |||||||||||||||
|
I started seeing it after I took those steps. Unfortunately since it happens sporadically during high load (20.000+ calls per 5 minutes), I didn't see which of the steps that caused it. | |||||||||||||||
| Comment by Jeffrey Yemin [ 03/May/19 ] | |||||||||||||||
|
backend@reshopper.com: you've been seeing this since before you took any of the steps listed above, and are still seeing it after all those steps? If so, I'm not clear how any of them could be considered the cause. Can you clarify? | |||||||||||||||
| Comment by Mathias Lorenzen [ 03/May/19 ] | |||||||||||||||
|
I am also having the same issue - same stacktrace as Pakpoom. Things I've done since the issue started happening (perhaps some of these things can be the cause?):
I used to use mixed sync and async operations, but now even with fully async, it still occurs sometimes. Oh, and all my NuGet packages are up to date, and I am using Atlas with the latest MongoDB version. | |||||||||||||||
| Comment by Pakpoom Suksomrat [ 06/Sep/18 ] | |||||||||||||||
|
I am also facing the same issue. Here is the stack trace of the innermost exception:
and the stack trace of the outermost exception:
|