Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Add errorHandler to connect arguments #94

Closed
wants to merge 1 commit into from

Conversation

chiaolun
Copy link

Attach an error handler before connecting, otherwise errors from the connection could be emitted before a handler is attached, causing node process to exit.

@aricart
Copy link
Member

aricart commented Jun 16, 2020

@chiaolun the connection is resolved or rejected in a promise, so the event handler is not needed in the initial connection, and the reason why you cannot install it until the connection resolves.

@aricart aricart closed this Jun 16, 2020
@chiaolun
Copy link
Author

The specific error that was crashing our server before the error handler could be attached was an "Authentication Timeout" coming from the Socket, which was thrown from processInbound right here:
https://github.com/nats-io/nats.ts/blob/v1.2.4/src/protocolhandler.ts#L642

It isn't thrown from the connect function, it goes into the client EventEmitter.

trace (v1.2.4):

    at ts-nats.lib:protocolhandler.Object.handlers.data (app:///node_modules/ts-nats/lib/protocolhandler.js:445:18)
    at ts-nats.lib:protocolhandler.ProtocolHandler.processInbound (app:///node_modules/ts-nats/lib/protocolhandler.js:580:34)
    at ts-nats.lib:protocolhandler.ProtocolHandler.processErr (app:///node_modules/ts-nats/lib/protocolhandler.js:905:35)
    at ts-nats.lib:protocolhandler.Function.toError (app:///node_modules/ts-nats/lib/protocolhandler.js:894:20)```

@aricart aricart reopened this Jun 16, 2020
@aricart
Copy link
Member

aricart commented Jun 16, 2020

@chiaolun OK, that makes sense - the fix will need to be different than what you are proposing here. I have opened #95.

@chiaolun
Copy link
Author

Thank you!

@chiaolun chiaolun closed this Jun 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants