Skip to content

Commit 6bc620a

Browse files
authored
Merge pull request #1875 from murgatroid99/grpc-js_client_call_write_error
grpc-js: Handle errors thrown by writing to http2 stream
2 parents 4d69637 + ce2765f commit 6bc620a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/grpc-js/src/call-stream.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,15 @@ export class Http2CallStream implements Call {
637637
this.pendingWrite.length +
638638
' (deferred)'
639639
);
640-
stream.write(this.pendingWrite, this.pendingWriteCallback);
640+
try {
641+
stream.write(this.pendingWrite, this.pendingWriteCallback);
642+
} catch (error) {
643+
this.endCall({
644+
code: Status.UNAVAILABLE,
645+
details: `Write failed with error ${error.message}`,
646+
metadata: new Metadata()
647+
});
648+
}
641649
}
642650
this.maybeCloseWrites();
643651
}
@@ -762,7 +770,15 @@ export class Http2CallStream implements Call {
762770
this.pendingWriteCallback = cb;
763771
} else {
764772
this.trace('sending data chunk of length ' + message.message.length);
765-
this.http2Stream.write(message.message, cb);
773+
try {
774+
this.http2Stream.write(message.message, cb);
775+
} catch (error) {
776+
this.endCall({
777+
code: Status.UNAVAILABLE,
778+
details: `Write failed with error ${error.message}`,
779+
metadata: new Metadata()
780+
});
781+
}
766782
this.maybeCloseWrites();
767783
}
768784
}, this.handleFilterError.bind(this));

0 commit comments

Comments
 (0)