You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing error handling logic. When I introduce in issue with the nkey I Get an error
nats: Permissions Violation for Subscription to "my..my." on connection [267]
But I can't handle the error from SubscribeSync (or Subscribe, I've tried both)
subscriptions[name], err = nc.SubscribeSync(prefix)
if err != nil {
errString := fmt.Sprintf("Message bus error: Subscription failed: subject=%s, prefix=%s, error=%v", "subject", prefix, err)
return errString, "Not Connected"
}
time.Sleep(100 * time.Millisecond) ----> Added so I can catch the errorin nc.LastError(), otherwise the error is never caught.
lastError := nc.LastError()
if lastError != nil {
errString := fmt.Sprintf("Message bus error: %s", lastError.Error())
return errString, "Not Connected"
}
Expected behavior
Expected behavior would be the error being returned here.
Error
nats: Permissions Violation for Subscription to "agent.c4b976da-5cbf-4628-b46d-5d794c929b07.agent.c4b976da-5cbf-4628-b46d-5d794c929b07" on connection [267]
Should be returned and handled.
Server and client version
Golang code I am writing is
github.com/nats-io/nats.go v1.31.0
I think this is what the server side is getting, but I don't have access to the nats-server to run the nats-server --version command.
go install github.com/nats-io/nats-server/v2@latest
Host environment
Client is running in
Linux 6.2.0-1019-azure x86_64
go version go1.21.7 linux/amd64
Steps to reproduce
When everything works there is no issue at all.
But when the myID is changed to something it isn't suppose to be, there is an error that if the time.sleep isn't introduced, does not get caught. The error should be returned by the call to nc.SubscribeSync(prefix). lastError can't catch the error unless the sleep is introduced. After the time.sleep the error comes up
nats: Permissions Violation for Subscription to "my..my." on connection [295]
Hey @chadglaser4682, thanks for reporting the issue. I agree that handling subscription errors on nc isn't ideal, especially since you have to introduce delays to catch it. We are working of a way to localize the errors to be coupled with the subscription, I'll let you know here when I have something.
Hey,
I just stumbled over the same problem. Is there a workaround in the meantime to catch such an error? I would like to terminate my service in such a case as the subscription won't work properly. I saw that I can catch the error asynchronously by defining a AsyncErrorCB function in the nats connection. Is it fine to assume that any error routed through that function should result in a service termination? Or do I need to match the error message as some errors are expected to be only temporary?
Hey @SimonSchmid probably you should match errors as some of them can be transtient, e.g. nats.ErrSlowConsumer which is a client-side slow consumer error which is recoverable but does mean you are dropping some messages. Another example of non-terminal error is nats.ErrBadHeaderMsg if headers decoding fails for incoming message (although this one should not be too common).
For non-recoverable errors I would match mostly against auth errors, so nats.ErrAuthorization, nats.ErrAuthExpired, nats.ErrAuthRevoked, nats.ErrAccountAuthExpired.
Observed behavior
I am writing error handling logic. When I introduce in issue with the nkey I Get an error
nats: Permissions Violation for Subscription to "my..my." on connection [267]
But I can't handle the error from SubscribeSync (or Subscribe, I've tried both)
Expected behavior
Expected behavior would be the error being returned here.
subscriptions[name], err = nc.SubscribeSync(prefix)
if err != nil {
errString := fmt.Sprintf("Message bus error: Subscription failed: subject=%s, prefix=%s, error=%v", "subject", prefix, err)
return errString, "Not Connected"
}
Error
nats: Permissions Violation for Subscription to "agent.c4b976da-5cbf-4628-b46d-5d794c929b07.agent.c4b976da-5cbf-4628-b46d-5d794c929b07" on connection [267]
Should be returned and handled.
Server and client version
Golang code I am writing is
github.com/nats-io/nats.go v1.31.0
I think this is what the server side is getting, but I don't have access to the nats-server to run the nats-server --version command.
Host environment
Client is running in
Linux 6.2.0-1019-azure x86_64
go version go1.21.7 linux/amd64
Steps to reproduce
When everything works there is no issue at all.
But when the myID is changed to something it isn't suppose to be, there is an error that if the time.sleep isn't introduced, does not get caught. The error should be returned by the call to nc.SubscribeSync(prefix). lastError can't catch the error unless the sleep is introduced. After the time.sleep the error comes up
nats: Permissions Violation for Subscription to "my..my." on connection [295]
func checkNatsConnection(config *config)(string, string)
natsConnector := msgbus.NatsConnection{}
var subscriptions = make(map[string]*nats.Subscription)
mySubject := "my." + config.myID
name := "my." + config.myID
}
The text was updated successfully, but these errors were encountered: