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

With a NATS server with JetStream disabled jetstream package functions always returns context deadline exceeded #1565

Closed
johbar opened this issue Feb 25, 2024 · 5 comments · Fixed by #1605
Labels
defect Suspected defect such as a bug or regression

Comments

@johbar
Copy link
Contributor

johbar commented Feb 25, 2024

Observed behavior

When starting a NATS server with JetStream disabled, the jetstream package client operations always seem to return context.deadlineExceededError instead of specialized errors.

Expected behavior

Functions like AccountInfo(ctx context.Context) should return ErrJetStreamNotEnabled.

Server and client version

github.com/nats-io/nats.go v1.33.1
server version 2.10.11

Host environment

go version go1.22.0 linux/amd64
Server running on Podman v4.8.3

Steps to reproduce

Start Server with podman run --rm -it -p 4222:4222 nats:latest.

Quick and dirty client code:

package main

import (
	"context"
	"testing"

	"github.com/nats-io/nats.go"
	"github.com/nats-io/nats.go/jetstream"
)

func TestNatsClient(t *testing.T) {
	nc, _ := nats.Connect("nats://localhost:4222")
	js, _ := jetstream.New(nc)
	_, err := js.AccountInfo(context.TODO())
	t.Error(err)
}

Output:

--- FAIL: TestNatsClient (5.00s)
    .../client_test.go:15: context deadline exceeded

I also tried to unwrap and convert the error with no success.

@johbar johbar added the defect Suspected defect such as a bug or regression label Feb 25, 2024
@piotrpio
Copy link
Collaborator

Hello @johbar , thank you for submitting the issue. I'll take a look at this.

@piotrpio
Copy link
Collaborator

Ok, so I looked at this issue and this is caused by the the fact that the nats docker image by default starts in clustered mode: https://hub.docker.com/_/nats

In clustered mode, server behaves differently then in standalone mode - it will not return "JetStream not enabled" to the client because there may be another server in the cluster with JetStream enabled. Since there is none, the request eventually times out and thus context deadline exceeded error.

There is not much that can be done about this unfortunately. If you don't need clustered JetStream, you may want to consider using a standalone server instead and get proper errors.

@johbar
Copy link
Contributor Author

johbar commented Feb 27, 2024

Hi @piotrpio, thank you for that investigation.

I considered opening another issue requesting something like a IsJetStreamEnabled method I could call on a NatsConnection object. But then I realized: Due to the dynamic distributed nature of NATS it is not possible to say if JetStream is "enabled in the cluster". At any point in time a JetStream-enabled node can join or leave the cluster. So this is exactly the issue here.

Nevertheless, it is a bit unsatisfying if we only get a timeout, especially in a rather static clustered setup, that could, for whatever reason, be misconfigured. But if it is not possible to return a more specific error, I think at least some docs should be revised. Like ErrJetStreamNotEnabled should have a hint when not to expect that error. Also the AccountInfo comment should be clear about that.

@piotrpio
Copy link
Collaborator

You're right, I'll update the docs to make it clear 👍

@piotrpio
Copy link
Collaborator

piotrpio commented Apr 5, 2024

I've updated the docs.

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