Skip to content

Commit

Permalink
Merge pull request grpc#189 from Runar1/master
Browse files Browse the repository at this point in the history
Fixed bug where we got unhandled promise rejections in fetch pump
  • Loading branch information
Jonny Reeves authored Sep 5, 2018
2 parents cfc0b9e + 7864e1d commit 9892a51
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ts/src/transports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ class Fetch implements Transport {
});
this.pump(this.reader, res);
return;
})
.catch(err => {
if (this.cancelled) {
this.options.debug && debug("Fetch.catch - request cancelled");
return;
}
this.cancelled = true;
this.options.debug && debug("Fetch.catch", err.message);
detach(() => {
this.options.onEnd(err);
});
});
}

Expand All @@ -69,6 +80,7 @@ class Fetch implements Transport {
this.options.debug && debug("Fetch.catch - request cancelled");
return;
}
this.cancelled = true;
this.options.debug && debug("Fetch.catch", err.message);
detach(() => {
this.options.onEnd(err);
Expand All @@ -89,6 +101,10 @@ class Fetch implements Transport {
}

cancel() {
if (this.cancelled) {
this.options.debug && debug("Fetch.abort.cancel already cancelled");
return;
}
this.cancelled = true;
if (this.reader) {
// If the reader has already been received in the pump then it can be cancelled immediately
Expand Down

0 comments on commit 9892a51

Please sign in to comment.