fix(instrumentation-fetch): do not modify the returned type of fetch#6521
Conversation
fetch returns a native promise. If we wrap that promise, any code that checks if a promise is native will fail. Notably this happens in the case of WebAssembly.compileStreaming
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (56.25%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #6521 +/- ##
==========================================
- Coverage 95.73% 95.67% -0.07%
==========================================
Files 364 364
Lines 12104 12069 -35
Branches 2887 2876 -11
==========================================
- Hits 11588 11547 -41
- Misses 516 522 +6
🚀 New features to boost your workflow:
|
| throw error; | ||
| } | ||
|
|
||
| return new Promise((resolve, reject) => { |
There was a problem hiding this comment.
new Promise not required because context.with returns its callback return value synchronously, which is already a Promise
raphael-theriault-swi
left a comment
There was a problem hiding this comment.
LGTM, personally got no objection to the cancellation stuff. I'd still like a 2nd review from someone else with more familiarity with this code is possible though.
|
@overbalance updated the PR. PTAL |
overbalance
left a comment
There was a problem hiding this comment.
A runtime guard on error.status is probably overkill. Looks good!
c846919
fetch returns a native promise. If we wrap that promise, any code that checks if a promise is native will fail. Notably this happens in the case of WebAssembly.compileStreamingfetch returns a
Promise<Response>. When we wrapfetchwe also wrap theResponse. It used to be wrapped in a newResponseobject. Recently in #6343 aProxywas introduced so that certain readonly properties could be retained.This fix works by removing the
Proxyand returning the originalResponse. The downside is that if the user cancels the request reader withreader.cancel(), our clone will not be cancelled and the clone will continue to read until the underlying stream is closed (most likely by the server finishing the response).AbortController.abort()still works because it aborts the underlying fetch, closing both the original and clone streams immediately, which is the typical way to abort a fetch anyway.Fixes #6518