Skip to content
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

node.js UnhandledPromiseRejectionWarning #878

Closed
uranik777 opened this issue Jan 20, 2021 · 3 comments
Closed

node.js UnhandledPromiseRejectionWarning #878

uranik777 opened this issue Jan 20, 2021 · 3 comments

Comments

@uranik777
Copy link

uranik777 commented Jan 20, 2021

sometimes the nodejs program crashes on reconnect attemt

await xmpp.stop();
while(xmpp.status!=='offline'){
await sleep(500);
}
try{
await xmpp.start(); // <<< unhandled error here (I do not know why error not catch in try block)
}catch (e) {
console.error(e);
}

with error:
(node:10315) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at writeAfterEnd (_stream_writable.js:266:14)
at TLSSocket.Writable.write (_stream_writable.js:315:5)
at /home/ubuntu/node/node_modules/@xmpp/connection/index.js:342:19
at new Promise ()
at Client.write (/home/ubuntu/node/node_modules/@xmpp/connection/index.js:334:12)
at Client.open (/home/ubuntu/node/node_modules/@xmpp/connection/index.js:266:16)
at Client.start (/home/ubuntu/node/node_modules/@xmpp/connection/index.js:216:16)

@sonnyp
Copy link
Member

sonnyp commented Jan 20, 2021

Please format your issue correctly next time, see https://guides.github.com/features/mastering-markdown/

xmpp.js implements reconnect by default - you are probably messing with it

See
https://github.com/xmppjs/xmpp.js/tree/master/packages/client
and
https://github.com/xmppjs/xmpp.js/tree/master/packages/reconnect

@sonnyp sonnyp closed this as completed Jan 20, 2021
@uranik777
Copy link
Author

uranik777 commented Jan 24, 2021

it would still be good to catch the exception
(node:3432) 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#cl
i_unhandled_rejections_mode). (rejection id: 67)
node_modules/@xmpp/connection/index.js:49
this.parser.write(str);
TypeError: Cannot read property 'write' of null

i had to change the code to this:

    if(this.parser){
        this.parser.write(str);
    }

@sonnyp
Copy link
Member

sonnyp commented Jan 24, 2021

That's a different issue, see #866

BTW it's your application job to catch exceptions. xmpp.js can and will throw when an error occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants