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
server: on macOS, you can start two processes with the same --port as long as one specifies --listen-addr #40708
Comments
I think this may be macOS-specific and may be related to ipv6: https://stackoverflow.com/questions/51071020/golang-net-listen-binds-to-port-thats-already-in-use It looks like what may be happening is that it binds to ipv6 by default. IPv4 connections seem to be allowed (localhost-specific magic?) if there's nothing else bound to the ipv4 port, but it doesn't count as a conflict if there's something there. This seems like it's mainly suboptimal behavior in the kernel, but one thing we could do to work around it is to call |
We have marked this issue as stale because it has been inactive for |
yes this is working as intended - having two processes, one listening on 0.0.0.0:26257 and the other on 127.0.0.1:26257, is valid. |
It's a bit dismissive when two people who are not clueless are talking about an issue and the 3rd closes it by simply stating that it's working "as intended", because it begs the question of intended by whom? Also, you say it's intended and valid, but that's not how the system works on Linux - I've just tried and the second instance refuses to use the port. As Ben said, this seems to be a Mac only behavior. |
My point remains. It's a Macos thing that is intended by apple. You would get the same behavior with What do you think crdb should do about it? |
Well some low level behavior of some system call being "intended by Apple" does not generally translate into high-level CRDB behavior...
I've just tried, and I don't believe this to be true for Postgres. I've configured one pg server to bind to all interfaces, and another one to bind to localhost. If they're both trying to use the same port, the second one doesn't start. It says that another Postmaster is already using
One way or another, I would like for CRDB on OSX tro behave like it behaves on Linux (or at least how it appears to me to behave on Linux) - if I ask it to bind to all interfaces on port x, but it can't bind to some of them, I want it to fail. |
The behavior with "lock files" works with crdb already, if you let it configure a Unix socket. I remember ben was opposed to enabling the Unix socket by default, but maybe that would be a good use case for it. |
I agree with Andrei that I don't think we can call this "working as intended". Regardless of apple's intentions here, our intention is that if you ask us to bind on all interfaces, you should get an error unless we were able to bind the requested port on all interfaces. But it's a really weird edge case - how likely are you to hit this situation without roachprod setting |
Ben how do you feel about setting up the unix socket by default? |
I don't understand how a unix socket helps here. Note that the invocations here must be running in different working directories because we're not running into store-level lock files, so where would we put the unix socket to do something useful here? |
The unix socket is typically created in This is exactly the functionality that makes PostgreSQL (and presumably mysql and other db servers) work the way that andrei wants on macos. |
Unix sockets aren't great as lockfiles because they are often left behind if a process exits uncleanly. It's very common to blindly delete them (which is allowed, even if they are in use). If we turned on this socket automatically it would cause other headaches and we'd need to figure out a safe way to clean up. We shouldn't turn on unix sockets just because we want a lockfile. |
Ok I'm going to leave this issue open, but not touching this until we have a concrete, specific solution in mind with a clear analysis that it's not going to break existing behavior (e.g. the handling of auto-allocated port numbers). |
We have marked this issue as stale because it has been inactive for |
This has bit me several times already:
roachprod local
starts the first node asThis does not prevent you from starting another node as
It does, however, prevent you from starting a node as
This is most unfortunate, because on several occasions I had a
roachprod local
cluster running in the background, but then naively started another node for unrelated work, and tried to connect to it, only to connect to the wrong cluster.I'm assuming node startup doesn't fail as long as there's any interfaces on which the port is available. But I think it should fail if the port is taken on any interface, and force you to specify a
listen-addr
if you really want to do something funky.The code around this is very simple; we just call
net.Listen()
, which doesn't fail when I'd like it to fail.cockroach/pkg/server/server.go
Line 2230 in 57ca960
@bdarnell , do you happen to have any suggestion here? I'd be happy to implement it.
Epic: CRDB-549
Jira issue: CRDB-5519
The text was updated successfully, but these errors were encountered: