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

Publish RetryAttempt and RetryWait not working as expected #1664

Closed
sourabhaggrawal opened this issue Jun 25, 2024 · 9 comments
Closed

Publish RetryAttempt and RetryWait not working as expected #1664

sourabhaggrawal opened this issue Jun 25, 2024 · 9 comments
Assignees
Labels
defect Suspected defect such as a bug or regression

Comments

@sourabhaggrawal
Copy link

Observed behavior

js.Publish("test", []byte("hi"), nats.RetryWait(5*time.Second), nats.RetryAttempts(10))
It gives up at first attempt itself after waiting for 5 second.

Expected behavior

This supposed to retry 10 times if there is "no responder" error and should retry 5 times before it gives up. So after 50 seconds it should give up if there is "no responder" error on every attempt.

Server and client version

nats-server 2.10.3
nats-client 1.35.0

Host environment

Mac OS

Steps to reproduce

Publish a message to subject which is not associated to stream, configure retry attempt and retrywait.

js.Publish("test", []byte("hi"), nats.RetryWait(5*time.Second), nats.RetryAttempts(10))

@sourabhaggrawal sourabhaggrawal added the defect Suspected defect such as a bug or regression label Jun 25, 2024
@souravagrawal
Copy link

Raised a PR for same here #1667

@Jarema
Copy link
Member

Jarema commented Jul 2, 2024

The current bahavior is restrained by TTL that can be set by nats.AckWait().
The number of retries defines the upper bound for number of retries. TTL still applies.

@souravagrawal
Copy link

Any specific reason why it only retries in case of "No Responder" case. There can be many other cases too where user expect nats to retry publish.
Also this retry is not there in AsyncPublish method of go, however it is there in .net client https://github.com/nats-io/nats.net.v2/blob/ccc212f764508f11a3154ade8d29bfdbb772de02/src/NATS.Client.JetStream/NatsJSContext.cs#L120

@Jarema
Copy link
Member

Jarema commented Jul 4, 2024

Only retrying on no responders is safe.
Retrying on Timeout can lead to duplicate messages in the stream, as the operation can finish after client timeout window.

.net async publish is a publish that waits for the ack. The async part comes from the idiom in .net, meaning that it's async operation from .net perspective, not NATS idioms perspective.

We're trying to find a better name for async publish, meaning - a publish that does not wait for ack, but returnes a future of a kind ;).

@souravagrawal
Copy link

What are your thoughts on providing Retry Attempts in Async Publish ?

@sourabhaggrawal
Copy link
Author

@Jarema Currently async publish does not support retry, is there any plan to fix/add later.

@Jarema
Copy link
Member

Jarema commented Jul 9, 2024

@sourabhaggrawal at least the new jetstream package does support retries on async publish. Not sure about the legacy one.
Will defer that one to @piotrpio

@sourabhaggrawal
Copy link
Author

Great, can you share some example for async Publish using new jetstream api ?
TIA

@piotrpio
Copy link
Collaborator

piotrpio commented Aug 2, 2024

Hello @sourabhaggrawal, sorry for taking so long with this. Please see my reply here for an example using new JetStream API.

We'll also be adding the retries to the old API, but I'm not yet sure it'll make it to the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

4 participants