nats.js: Permissions Violation during subscribe unexpectedly closes the whole connection
- Client version: 2.8.0
- Node version: 16.14.2
What’s happening
If in subscription iterator for await (const message of subscription)
happens Permissions Violation error like this
NatsError: 'Permissions Violation for Subscription to "subject"'
at Function.toError (/code/node_modules/nats/lib/nats-base-client/protocol.js:306:20)
at ProtocolHandler.<anonymous> (/code/node_modules/nats/lib/nats-base-client/protocol.js:339:41)
at Generator.next (<anonymous>)
at /code/node_modules/nats/lib/nats-base-client/protocol.js:8:71
at new Promise (<anonymous>)
at __awaiter (/code/node_modules/nats/lib/nats-base-client/protocol.js:4:12)
at ProtocolHandler.processError (/code/node_modules/nats/lib/nats-base-client/protocol.js:337:16)
at ProtocolHandler.push (/code/node_modules/nats/lib/nats-base-client/protocol.js:426:22)
at Parser.parse (/code/node_modules/nats/lib/nats-base-client/parser.js:312:45)
at ProtocolHandler.<anonymous> (/code/node_modules/nats/lib/nats-base-client/protocol.js:189:45)
it will close the whole NATS connection. Here’s what connection.closed()
will yield (same error):
NatsError: 'Permissions Violation for Subscription to "subject"'
at Function.toError (/code/node_modules/nats/lib/nats-base-client/protocol.js:306:20)
at ProtocolHandler.<anonymous> (/code/node_modules/nats/lib/nats-base-client/protocol.js:339:41)
at Generator.next (<anonymous>)
at /code/node_modules/nats/lib/nats-base-client/protocol.js:8:71
at new Promise (<anonymous>)
at __awaiter (/code/node_modules/nats/lib/nats-base-client/protocol.js:4:12)
at ProtocolHandler.processError (/code/node_modules/nats/lib/nats-base-client/protocol.js:337:16)
at ProtocolHandler.push (/code/node_modules/nats/lib/nats-base-client/protocol.js:426:22)
at Parser.parse (/code/node_modules/nats/lib/nats-base-client/parser.js:312:45)
at ProtocolHandler.<anonymous> (/code/node_modules/nats/lib/nats-base-client/protocol.js:189:45)
What’s expected
I think closing the whole connection is very unexpected behavior here. While clearly, this is usually a human error when setting up NATS permissions, the fact that some subscriptions failed to doesn’t mean that the whole connection should be killed because other subs are still able to work. It should be up to the application to decide what to do in such situations.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (13 by maintainers)
Yeap, the issue is present only in v2.8.0.
With 2.8.1-2 I’m unable to reproduce it, so we’re good to go 👍
Going to put the same test in node, perhaps something is not quite right there.
@aricart