node-modbus-serial icon indicating copy to clipboard operation
node-modbus-serial copied to clipboard

Modbus/TCP: If the connection is broken, an unhandled promise rejection error is generated, and it can't be caught

Open ryangriggs opened this issue 4 years ago • 4 comments

If I disconnect the modbus/tcp device from the network, to test what happens, I am getting the following error:

(node:25171) UnhandledPromiseRejectionWarning: Error: TCP Connection Timed Out at Socket. (/home/pi/vision/node_modules/modbus-serial/ports/tcpport.js:111:24) at Socket.emit (events.js:315:20) at Socket._onTimeout (net.js:483:8) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7) (node:25171) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2041679)

This error seems to be un-catchable within my code, no matter where I add a try/catch block or promise .catch() statement, this error is still thrown.

Expected behavior: I should be able to catch and handle this error to avoid the unhandled promise rejection warning.

ryangriggs avatar Dec 22 '20 16:12 ryangriggs

hello, thank you for the issue !

can you make a pull request fixing that ?

yaacov avatar Dec 22 '20 16:12 yaacov

Working on it...

ryangriggs avatar Dec 22 '20 17:12 ryangriggs

From what I can tell, it appears this is a bug in request-promise-native (see https://github.com/request/request-promise-native/issues/31)

ryangriggs avatar Dec 22 '20 21:12 ryangriggs

I face the same issue. Would be great if this could be resolved.

romor avatar Jun 26 '22 07:06 romor