[wasm][http] Fix race condition as a result of using TaskCompletionSource: RangeError...
commit608c93643e98becb794e0ad53fb5e494224305d8
authorKenneth Pouncey <kjpou@pt.lu>
Fri, 29 Nov 2019 06:14:19 +0000 (29 07:14 +0100)
committerGitHub <noreply@github.com>
Fri, 29 Nov 2019 06:14:19 +0000 (29 07:14 +0100)
tree4de9baed94fa486fdc7f2489896be3a116364d55
parent59a9af6d7ce3ff7785e9038e3902fc77291475b8
[wasm][http] Fix race condition as a result of using TaskCompletionSource: RangeError: Maximum call stack size on Safari (#17946)

There is a race condition on Safari as a result of using TaskCompletionSource that causes a stack exceeded error being thrown during Blazor startup.

Safari throws the following error:

```
[Error] Unhandled Promise Rejection: RangeError: Maximum call stack size exceeded.
    step (blazor.webassembly.js:2530)
    fulfilled (blazor.webassembly.js:2500)
    promiseReactionJob

```

- Modify `WebAssemblyHttpMessageHandler.cs` to create the TaskCompletionSource to run continuations asynchronously.
   - `TaskCompletionSource<HttpResponseMessage>(TaskCreationOptions.RunContinuationsAsynchronously);`

- There is a second part to this on AspNetCore in `Renderer.cs` to process it's pending startup tasks to run continuations asynchronously to compliment the TaskCompetionSource of the Http response message.

The following link discusses the potential stack/race problem that can occur when using TaskCompletionSource:  https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/
sdks/wasm/framework/src/WebAssembly.Net.Http/WasmHttpMessageHandler.cs