Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public async Task<HttpResponseMessage> SendRequestAsync(HttpRequestMessage reque
cancellationToken.ThrowIfCancellationRequested();

var response = new HttpResponseMessage((HttpStatusCode)incomingResponse.Status());
WasiHttpInterop.ConvertResponseHeaders(incomingResponse, response);


// request body could be still streaming after response headers are received and started streaming response
// we will leave scope of this method
// we need to pass the ownership of the request and this wrapper to the response (via response content stream)
// unless we know that we are not streaming anymore
incomingStream = new WasiInputStream(this, incomingResponse.Consume());// passing self ownership, passing body ownership
response.Content = new StreamContent(incomingStream); // passing incomingStream ownership to SendAsync() caller
WasiHttpInterop.ConvertResponseHeaders(incomingResponse, response);

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal static class WasiEventLoop
// it will be leaked and stay in this list forever.
// it will also keep the Pollable handle alive and prevent it from being disposed
private static readonly List<PollableHolder> s_pollables = new();
private static bool s_tasksCanceled;

internal static Task RegisterWasiPollableHandle(int handle, CancellationToken cancellationToken)
{
Expand All @@ -35,6 +36,11 @@ internal static Task RegisterWasiPollable(Pollable pollable, CancellationToken c
internal static void DispatchWasiEventLoop()
{
ThreadPoolWorkQueue.Dispatch();
if (s_tasksCanceled)
{
s_tasksCanceled = false;
return;
}

var holders = new List<PollableHolder>(s_pollables.Count);
var pending = new List<Pollable>(s_pollables.Count);
Expand Down Expand Up @@ -114,6 +120,11 @@ private static void CancelAndDispose(object? s)
return;
}

// Tell event loop to exit early, giving the application a
// chance to quit if the task(s) it is interested in have
// completed.
s_tasksCanceled = true;

// it will be removed from s_pollables on the next run
self.isDisposed = true;
self.pollable.Dispose();
Expand Down