Skip to content

Commit

Permalink
fix: [#6683] Timeout issue when using DLASE (#6696)
Browse files Browse the repository at this point in the history
* Add Http 202 (Accepted) for DLASE

* Fix unit tests
  • Loading branch information
sw-joelmut committed Oct 6, 2023
1 parent c2f3aea commit 046725a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +92,7 @@ public async Task<ReceiveResponse> 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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 046725a

Please sign in to comment.