Fix race condition in SSE GET request initialization (#1212)

This commit is contained in:
Stephen Toub 2026-01-29 23:04:51 -05:00 • committed by GitHub
commit f9dec13660
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -125,6 +125,12 @@ public sealed class StreamableHttpServerTransport : ITransport
var primingItem = await _storeSseWriter.WriteEventAsync(SseItem.Prime<JsonRpcMessage>(), cancellationToken).ConfigureAwait(false);
await _httpSseWriter.WriteAsync(primingItem, cancellationToken).ConfigureAwait(false);
}
else
{
// If there's no priming write, flush the stream to ensure HTTP response headers are
// sent to the client now that the transport is ready to accept messages via SendMessageAsync.
await sseResponseStream.FlushAsync(cancellationToken).ConfigureAwait(false);
}
}
// Wait for the response to be written before returning from the handler.