mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: fix RoundTrip context cancellation for js/wasm
The existing js/wasm implementation of RoundTrip calls abort() on the fetch() call when the context is canceled but does not wait for for the resulting promise to be rejected. The result is the failure callback for the promise will be called at some later point in time when the promise rejection is handled. In some case this callback may be called after the Go program has exited resulting in "Go program has already exited" errors. Fixes #57098 Change-Id: Ia37fd22cb9f667dbb0805ff5db0ceb8fdba7246b Reviewed-on: https://go-review.googlesource.com/c/go/+/680937 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
parent
d9d2cadd63
commit
fdc076ce76
1 changed files with 8 additions and 0 deletions
|
|
@ -236,6 +236,14 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
|
|||
if !ac.IsUndefined() {
|
||||
// Abort the Fetch request.
|
||||
ac.Call("abort")
|
||||
|
||||
// Wait for fetch promise to be rejected prior to exiting. See
|
||||
// https://github.com/golang/go/issues/57098 for more details.
|
||||
select {
|
||||
case resp := <-respCh:
|
||||
resp.Body.Close()
|
||||
case <-errCh:
|
||||
}
|
||||
}
|
||||
return nil, req.Context().Err()
|
||||
case resp := <-respCh:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue