-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error: connect ECONNREFUSED 127.0.0.1:port for request inside exit event listener for v6.1.0 #127
Comments
This is caused by sync-rpc's attempts to do cleanup. If you attache the console.log('Process started');
process.on('exit', () => {
try {
let res = syncRequest('GET', 'https://jsonplaceholder.typicode.com/users/1');
console.log(JSON.parse(res.getBody()));
} catch(err) {
console.log('Got error');
console.log(err);
}
});
const syncRequest = require('sync-request');
throw new Error('Boo'); If you can find a way to make this work regardless of ordering, I'd accept a PR to http://github.com/ForbesLindesay/sync-rpc. It would probably need to change https://github.com/ForbesLindesay/sync-rpc/blob/f500876453721b37376419ad855388aae0579ccf/lib/index.js#L38-L40 to give other process.on handlers a chance to run first. |
@ForbesLindesay, thanks for the response. Your solution works, also another way can be to put the exit event listener using Also there is similar issue with |
Tested little bit more for const syncRequest = require('sync-request'); // v6.1.0
console.log('Process started');
process.on('SIGINT', () => {
console.log('got SIGINT');
try {
let res = syncRequest('GET', 'https://jsonplaceholder.typicode.com/users/1');
console.log(JSON.parse(res.getBody()));
} catch(err) {
console.log('Got error');
console.log(err);
}
});
setTimeout(() => {
console.log('timeout boo');
}, 6000); In windows above works till node version 8.11.4, and from 8.12.0 it stops working. Error is similar to exit:
|
I think any kind of execution during exit is going to be a special case for sync-rpc. The problem is that one of the cleanup tasks we must do is killing the child process we spawn to handle the requests. There's no clean way I can think of for you to indicate that you have other cleanup tasks that must complete first. |
That makes sense, thanks @ForbesLindesay, feel free to close the issue. |
I'm trying to send some request on the exit event.
This works for the sync-request version 4.0.0 but fails for the 6.1.0.
Error for 6.1.0:
Expected output as per 4.0.0:
Is child process getting killed before it's able to make the request? Not sure why it would work for the older version though. Let me know if any more info is needed.
Node: 8.14.0
Os: win7
The text was updated successfully, but these errors were encountered: