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

KV watch functionality fails when NATS server restarts #688

Closed
ThalesValentim opened this issue Apr 22, 2024 · 3 comments · Fixed by #689
Closed

KV watch functionality fails when NATS server restarts #688

ThalesValentim opened this issue Apr 22, 2024 · 3 comments · Fixed by #689
Labels
defect Suspected defect such as a bug or regression

Comments

@ThalesValentim
Copy link

ThalesValentim commented Apr 22, 2024

Observed behavior

When watching for KV updates and the NATS server restarts, the client reconnects successfully but API throws the error:

{
   code: 400,
   err_code: 10013,
   description: 'consumer name already in use'
 }

Debug logs show that it tries to reconnect twice, with the same request data, when the watch method has been called.

Expected behavior

It should reconnect and continue receiving KV updates

Server and client version

nats-server 2.10.14
nats.js 2.22.0

Host environment

Unix OS

Steps to reproduce

From the KV example, the code to reproduce looks like:

const nats = require('./lib/src/mod.js');
const nc = await nats.connect();
const sc = nats.StringCodec();
const js = nc.jetstream();
const kv = await js.views.kv("testing");
await kv.create("hello.world", sc.encode("hi"));

const watch = await kv.watch();
(async () => {
  for await (const e of watch) {
    // do something with the change
    console.log(
      `watch: ${e.key}: ${e.operation} ${e.value ? sc.decode(e.value) : ""}`,
    );
  }
})().then();
  1. Run the example app
  2. Restart NATS server
  3. The client reconnects but the watch functionality fails with the response:

{"type":"io.nats.jetstream.api.v1.consumer_create_response","error":{"code":400,"err_code":10013,"description":"consumer name already in use"}}

Any ideas? Thanks!

@ThalesValentim ThalesValentim added the defect Suspected defect such as a bug or regression label Apr 22, 2024
@aricart
Copy link
Member

aricart commented Apr 22, 2024

The watcher is R1, so when your server restarts it is gone. There's no option for listening on the idle heartbeats - so that means that the watcher just stalls.... Let me see what I can do

@ThalesValentim
Copy link
Author

The watcher is R1, so when your server restarts it is gone. There's no option for listening on the idle heartbeats - so that means that the watcher just stalls.... Let me see what I can do

Thanks for your reply!

Let me give you some context. For every NATS server release, we expect to follow the changes and upgrade the NATS to the latest release, but currently, it affects clients that watch updates on KV. It would be great to handle that situation. Would you have a workaround in mind?

@aricart
Copy link
Member

aricart commented Apr 22, 2024

but of course - the question is how to onboard the change - looking at it.

aricart added a commit that referenced this issue Apr 22, 2024
…use the server would report the consumer as existing

[FIX] [JS] [KV] watcher reset if successful, could still get heartbeat missing reports which would cause the ordered consumer to reset when it didn't need to.

Fix #688
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

Successfully merging a pull request may close this issue.

2 participants