Skip to content

Commit acd3d5e

Browse files
committed
Fix a possible timeout with gss/sspi auth (#5028)
Fixes #4888 (cherry picked from commit ae3309f)
1 parent 597c481 commit acd3d5e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Npgsql/Internal/NpgsqlConnector.Auth.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,15 @@ async Task AuthenticateGSS(bool async)
299299
var response = ExpectAny<AuthenticationRequestMessage>(await ReadMessage(async), this);
300300
if (response.AuthRequestType == AuthenticationRequestType.AuthenticationOk)
301301
break;
302-
var gssMsg = response as AuthenticationGSSContinueMessage;
303-
if (gssMsg == null)
302+
if (response is not AuthenticationGSSContinueMessage gssMsg)
304303
throw new NpgsqlException($"Received unexpected authentication request message {response.AuthRequestType}");
305304
data = authContext.GetOutgoingBlob(gssMsg.AuthenticationData.AsSpan(), out statusCode)!;
306-
if (statusCode == NegotiateAuthenticationStatusCode.Completed)
305+
if (statusCode is not NegotiateAuthenticationStatusCode.Completed and not NegotiateAuthenticationStatusCode.ContinueNeeded)
306+
throw new NpgsqlException($"Error while authenticating GSS/SSPI: {statusCode}");
307+
// We might get NegotiateAuthenticationStatusCode.Completed but the data will not be null
308+
// This can happen if it's the first cycle, in which case we have to send that data to complete handshake (#4888)
309+
if (data is null)
307310
continue;
308-
Debug.Assert(statusCode == NegotiateAuthenticationStatusCode.ContinueNeeded);
309311
await WritePassword(data, 0, data.Length, async, UserCancellationToken);
310312
await Flush(async, UserCancellationToken);
311313
}

0 commit comments

Comments
 (0)