Skip to content

Commit dd01b55

Browse files
dicejcampersaupavelsavara
authored
[WASI] fix response header conversion and event loop (#107162)
Co-authored-by: campersau <[email protected]> Co-authored-by: Pavel Savara <[email protected]>
1 parent 144315f commit dd01b55

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public async Task<HttpResponseMessage> SendRequestAsync(HttpRequestMessage reque
5454
cancellationToken.ThrowIfCancellationRequested();
5555

5656
var response = new HttpResponseMessage((HttpStatusCode)incomingResponse.Status());
57-
WasiHttpInterop.ConvertResponseHeaders(incomingResponse, response);
58-
57+
response.RequestMessage = request;
5958

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

6767
return response;
6868
}

src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiEventLoop.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal static class WasiEventLoop
1414
// it will be leaked and stay in this list forever.
1515
// it will also keep the Pollable handle alive and prevent it from being disposed
1616
private static readonly List<PollableHolder> s_pollables = new();
17+
private static bool s_tasksCanceled;
1718

1819
internal static Task RegisterWasiPollableHandle(int handle, CancellationToken cancellationToken)
1920
{
@@ -35,6 +36,11 @@ internal static Task RegisterWasiPollable(Pollable pollable, CancellationToken c
3536
internal static void DispatchWasiEventLoop()
3637
{
3738
ThreadPoolWorkQueue.Dispatch();
39+
if (s_tasksCanceled)
40+
{
41+
s_tasksCanceled = false;
42+
return;
43+
}
3844

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

123+
// Tell event loop to exit early, giving the application a
124+
// chance to quit if the task(s) it is interested in have
125+
// completed.
126+
s_tasksCanceled = true;
127+
117128
// it will be removed from s_pollables on the next run
118129
self.isDisposed = true;
119130
self.pollable.Dispose();

0 commit comments

Comments
 (0)