diff --git a/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs b/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs index 6d0027e414..c691b19183 100644 --- a/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs +++ b/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Runtime.InteropServices; using System.Text.Json; using System.Threading; @@ -91,7 +92,7 @@ public async Task SendRequestAsync(StreamingRequest request, Ca } } - return await responseCompletionSource.Task.DefaultTimeOutAsync().ConfigureAwait(false); + return await responseCompletionSource.Task.DefaultTimeOutAsync().ConfigureAwait(false); } public async Task SendResponseAsync(Header header, StreamingResponse response, CancellationToken cancellationToken) @@ -194,6 +195,11 @@ public virtual void ReceiveResponse(Header header, ReceiveResponse response) Log.PayloadReceived(_logger, header); + if (response.StatusCode == (int)HttpStatusCode.Accepted) + { + return; + } + lock (_receiveSync) { if (!response.Streams.Any()) @@ -358,6 +364,8 @@ private void ProcessRequest(Guid id, ReceiveRequest request) { _ = Task.Run(async () => { + // Send an HTTP 202 (Accepted) response right away, otherwise, while under high streaming load, the conversation times out due to not having a response in the request/response time frame. + await SendResponseAsync(new Header { Id = id, Type = PayloadTypes.Response }, new StreamingResponse { StatusCode = (int)HttpStatusCode.Accepted }, _connectionCancellationToken).ConfigureAwait(false); var streamingResponse = await _receiver.ProcessRequestAsync(request, null).ConfigureAwait(false); await SendResponseAsync(new Header() { Id = id, Type = PayloadTypes.Response }, streamingResponse, _connectionCancellationToken).ConfigureAwait(false); diff --git a/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs b/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs index 8ec11383b6..d18e01b511 100644 --- a/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs +++ b/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Net; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -75,6 +76,11 @@ private async Task OnReceiveRequestAsync(Guid id, ReceiveRequest request) private async Task OnReceiveResponseAsync(Guid id, ReceiveResponse response) { + if (response.StatusCode == (int)HttpStatusCode.Accepted) + { + return; + } + // we received the response to something, signal it await _requestManager.SignalResponseAsync(id, response).ConfigureAwait(false); }