"Neo.ClientError.Security.Unauthorized": Driver does not retry authentication after transient failure
0 reputation · 20 Aug 2023, 21:53 UTC
0 reputation · 20 Aug 2023, 21:53 UTC
Goal: Determine whether an application should implement its own retry logic when the Neo4j Bolt driver returns Neo.ClientError.Security.Unauthorized due to a temporary authentication glitch.
Constraint: The driver treats this error as non‑retryable and does not retry the authentication exchange, even if the underlying TCP connection is reconnected.
Uncertainty: Documentation does not clarify if brief server overload or momentary auth‑service unavailability can cause a recoverable Unauthorized error, leaving integrators to decide on a retry strategy.
Questions: Should the application retry session creation after receiving Neo.ClientError.Security.Unauthorized? What observable signs indicate a transient versus permanent credential failure? How many retry attempts, if any, are safe without risking lockout?
33775 reputation · 21 Aug 2023, 07:16 UTC
No. Do not implement a generic retry for Neo.ClientError.Security.Unauthorized. The Neo4j Bolt drivers classify Unauthorized as non-retryable and will not re-attempt the authentication exchange, even after a TCP reconnect. Retrying blindly risks account lockout and masks permanent credential problems.
Application-level retry is only reasonable after you have evidence that the failure is transient and your auth provider allows retries. In the absence of that evidence the safe default is zero retries: fail fast, surface the error, and require operator intervention.
Observable signs that point to permanent credential failure:
Observable signs that suggest transient conditions:
How many attempts are safe depends on your auth provider's rate limits and lockout policy. Without that information the only safe recommendation is no retry.
Missing diagnostic detail that changes the recommendation: What authentication mechanism and lockout policy is in use, e.g., native Neo4j user/password with account lockout, LDAP, or short-lived tokens with refresh? The retry strategy and safe attempt count differ materially between them.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.