]> Cypherpunks.ru repositories - gostls13.git/commit
net/http: release callbacks after fetch promise completes
authorDmitri Shuralyov <dmitshur@golang.org>
Sun, 29 Mar 2020 03:10:20 +0000 (23:10 -0400)
committerDmitri Shuralyov <dmitshur@golang.org>
Thu, 2 Apr 2020 23:01:56 +0000 (23:01 +0000)
commit886303004f06cfb3bcd0c1da92fe51f5eb1e3023
tree04153c30b60137825d33f4d0e9765f5b7a58b513
parent888a0c8ef6afb752aafd147eda40d62796d87cb3
net/http: release callbacks after fetch promise completes

When the request context was canceled, the Transport.RoundTrip method
could return before the fetch promise resolved. This would cause the
success and failure callback functions to get called after they've
been released, which in turn prints a "call to released function"
error to the console.

Avoid that problem by releasing the callbacks after the fetch promise
completes, by moving the release calls into the callbacks themselves.
This way we can still return from the Transport.RoundTrip method as
soon as the context is canceled, without waiting on the promise to
resolve. If the AbortController is unavailable and it's not possible to
abort the fetch operation, the promise may take a long time to resolve.

For #38003.

Change-Id: Ied1475e31dcba101b3326521b0cd653dbb345e1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/226204
Reviewed-by: Johan Brandhorst <johan.brandhorst@gmail.com>
Reviewed-by: Richard Musiol <neelance@gmail.com>
src/net/http/roundtrip_js.go