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
jetstream.PublishMsg
is not guaranteed to return ErrNoStreamResponse
when there is no stream configured
#1461
Comments
Unfortunately this issue is not something that can be solved client-side. When publishing a message to a stream, the client is essentially not aware whether there is an underlying stream or not. It simply publishes a standard NATS request (message with reply subject) on a stream's subject and waits for the response. If there is another non-jetstream subscription listening on this subject (and the stream does not exist), this will end with a timeout. The server is also not aware whether the request is jetstream specific or not, since this is a standard NATS message. To know for sure whether there is a stream with interest on the publish subject, we would have to send a separate JetStream request to get the streams, which is not something we want to do on each publish (or even after the timeout is hit). My suggestion would be to not use the same subject for both stream and standard NATS subscription. If you want a separate subscription to just do the logging, I would suggest creating a simple ephemeral consumer with |
I kinda figured. |
Agreed, docs can be improved. |
There are 3 ways a JS publish can fail and you must catch and log them all:
The first 2 cases are equivalent from the client application's perspective: either wait a few seconds and try again or give up. Will add something about this in the docs. |
Observed behavior
jetstream.PublishMsg
is not guaranteed to returnErrNoStreamResponse
when there is no stream configured.https://github.com/nats-io/nats.go/blob/v1.31.0/jetstream/publish.go#L189-L191
The client seems to rely on
ErrNoResponders
to indicate that "no response from stream". However, if another consumer is doing a simple subscribe on the same subject (i.e.nc.Subscribe(...)
then the server doesn't respond withErrNoResponders
.Since
ErrNoResponders
is in the critical path for retry logic, this also fails since there is no other indication that something failed.This became an issue when writing tests for our use of the new JetStream API. One of the tests attempts to handle the case where a stream was not configured for before publication of messages. However, I couldn't make this error bubble up. Turns out, the test harness also has a simple
nc.Subscribe("test.>")
to track expected messages counts and sometime content. This "outofband" tracking kept theErrNoResponders
from being sent. Even though this was just a unit test, there are cases in production where this could happen. For example we sometimes use a simple subscribe with only headers as a parallel audit capture log.Expected behavior
I expected
jetstream.PublishMsg
to returnErrNoStreamResponse
if there was no JetStream configured to consume the subject.Server and client version
client: v1.31.0
server: v2.10.3
Host environment
No response
Steps to reproduce
No response
The text was updated successfully, but these errors were encountered: