grpc / grpc/grpc-node

Client calls are escaping the request domain

Open
#47 0 comments 0 reactions 1 assignee Claimed by @murgatroid99 View on GitHub
Dominant language
TypeScript
Stars
4.8k
Forks
716
Avg merge
2d 3h
Merged PRs (30d)
10

Description

Client calls are escaping the domain making some of our apps to crash.

Similar to this problem https://github.com/mongodb/node-mongodb-native/pull/1184

I modified this [example](https://github.com/grpc/grpc/blob/master/examples/node/static_codegen/greeter_client.js) for demonstration:

```js
const domain = require('domain');
const d = domain.create();

const messages = require('./helloworld_pb');
const services = require('./helloworld_grpc_pb');
const grpc = require('grpc');

function main() {
const client = new services.GreeterClient('localhost:50051', grpc.credentials.createInsecure());
const request = new messages.HelloRequest();

client.sayHello(request, (err, response) => {
console.log('Greeting:', response.getMessage());
throw new Error('Break!'); // <-- This makes the app crash --
});

setInterval(() => {
console.log('app is running.');
}, 2000);
}

d.run(() => {
main();
});

// This should catch the error and recover
d.on('error', (error) => {
console.log('Something wrong happened, but I caught it here and recovered:', error);
main();
});
```

A workaround is to wrap the callback with `domain.bind`
```js
client.sayHello(request, process.domain.bind((err, response) => {
console.log('Greeting:', response.getMessage());
throw new Error('Break!');
}));
```

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.