grpc / grpc/grpc-node

grpc-js: sendStatus called twice after emitting server streaming error

Open
#1,399 1 comment 0 reactions 0 assignees View on GitHub
package: @grpc/grpc-js
Dominant language
TypeScript
Stars
4.8k
Forks
716
Avg merge
2d 3h
Merged PRs (30d)
10

Description

### Problem description
I don't think this causes any actual problems but I noticed if you emit an error on `ServerWritableStreamImpl` then it will handle the error but also call the `_final` method. This is probably triggered by the `this.end()` in the error handler, maybe it should be changed to `this.destroy()` to avoid `_final` getting called. This only happens for `call.emit('error', err)`, `call.destroy(err)` works fine.

Also the node.js docs [suggest](https://nodejs.org/api/stream.html#stream_errors_while_writing) that any errors inside a _write method should be passed to the callback instead of [emitting the error directly](https://github.com/grpc/grpc-node/blob/%40grpc/grpc-js%401.0.3/packages/grpc-js/src/server-call.ts#L191).

### Reproduction steps
Emit an error in a server streaming handler using `call.emit('error', err)`

### Environment
- OS name, version and architecture: macOS 10.15.4
- Node version: v12.16.2
- Package name and version @grpc/grpc-js@1.0.3

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.