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

Embedded nats server with opts.DontListen=true fails to connect to cluster #5174

Open
tpihl opened this issue Mar 5, 2024 · 4 comments
Open
Assignees
Labels
defect Suspected defect such as a bug or regression

Comments

@tpihl
Copy link

tpihl commented Mar 5, 2024

Observed behavior

For embedded server the opt.DontListen also blocks participating in a cluster.

We are trying to run embedded nats server as a cluster node only (no external access for clients) so we need to prevent listen for clients. We still need to be able to configure things like cluster and monitor and websocket and so on.

Expected behavior

opts.DontListen is expected to prevent the server from listening for clients (to be able to use InProcess connection instead).

Is there any other way to run the server with other services configured but without allowing clients to connect?

Server and client version

tested with nats-server v2.10.11 and inprocess client

Host environment

linux

Steps to reproduce

Running this code will in log show '[INF] Listening for route connections on 127.0.0.1:4248' and port 4248 is open

However, uncommenting the DontListen and running same code will not open port 4248 and nothing in log.

	route, err := url.Parse("nats://localhost:4246")
	if err != nil {
		panic(err)
	}

	opts := &server.Options{
		// DontListen: true,
		Cluster: server.ClusterOpts{
			Name: "test",
			Host: "127.0.0.1",
			Port: 4248,
		},
		Routes: []*url.URL{route},
	}
	srv, err := server.NewServer(opts)
	if err != nil {
		server.PrintAndDie(fmt.Sprintf("nats-server failed to start: %s", err.Error()))
	}

	srv.ConfigureLogger()
	srv.Start()
	nc, err := nats.Connect("", nats.InProcessServer(srv))
@tpihl tpihl added the defect Suspected defect such as a bug or regression label Mar 5, 2024
@ripienaar
Copy link
Contributor

The original motivation for this is to support platforms where it's not possible to open sockets (wasm) or not desirable (mobile).

So imo not opening any ports, including routes and gateways, is the desired behaviour for this

@tpihl
Copy link
Author

tpihl commented Mar 6, 2024

Hi @ripienaar @wallyqs @neilalexander,

So how do you run the embedded nats server WITHOUT opening the "normal" client port while still use the explicitly configured services?

@tpihl
Copy link
Author

tpihl commented Mar 10, 2024

Hi again @ripienaar,

I tried to understand and looked into the description of #2360, however it clearly states;

"2. DontListen options which tells the NATS server not to listen on the usual TCP listener."

Any other service can be turned off by not configuring it. So why should DontListen disable them if they are configured?

@ripienaar
Copy link
Contributor

Those are TCP listeners. So they are disabled.

Here's the motivator from the original PR:

able to cater for a variety of platforms where opening socket connections either doesn't make sense (mobile) or just isn't possible (WASM).

It's for where sockets isnt possible, all sockets.

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