Skip to content

Conversation

norio-nomura
Copy link
Contributor

Since we’re using a single accepting go routine on the port forwarder’s listener, SO_REUSEPORT is unnecessary.

Applying this change prevents the port forwarder from binding if the listening port is already listened by another process with SO_REUSEPORT, resulting in a "bind: address already in use" error.

Previously, if the listening port was listened by another process with SO_REUSEPORT, the port forwarder succeeded in binding, but the client’s connection could be handled by another process, leading to port forwarding issues without errors.

Since we’re using a single accepting go routine on the port forwarder’s listener, `SO_REUSEPORT` is unnecessary.

Applying this change prevents the port forwarder from binding if the listening port is already listened by another process with `SO_REUSEPORT`, resulting in a "bind: address already in use" error.

Previously, if the listening port was listened by another process with `SO_REUSEPORT`, the port forwarder succeeded in binding, but the client’s connection could be handled by another process, leading to port forwarding issues without errors.

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Oct 7, 2025
@AkihiroSuda AkihiroSuda requested a review from balajiv113 October 7, 2025 06:35
@norio-nomura
Copy link
Contributor Author

Previously, if the listening port was listened by another process with SO_REUSEPORT, the port forwarder succeeded in binding, but the client’s connection could be handled by another process, leading to port forwarding issues without errors.

This also may happen in guest OS on test-port-forwarding.pl because netcat-openbsd (nc in Ubuntu) uses SO_REUSEPORT.
https://git.launchpad.net/ubuntu/+source/netcat-openbsd/tree/netcat.c?h=ubuntu/plucky#n1055

Copy link
Member

@balajiv113 balajiv113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 8, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 8, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 8, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 8, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 9, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 9, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>

hack/test-port-forwarding.pl: Add a connection timeout option and relax it from 1 second to 2 seconds.

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 9, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>

hack/test-port-forwarding.pl: Add a connection timeout option and relax it from 1 second to 2 seconds.

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 9, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>

hack/test-port-forwarding.pl: Add a connection timeout option and relax it from 1 second to 3 seconds.

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
norio-nomura added a commit to norio-nomura/lima that referenced this pull request Oct 9, 2025
support `socat` as a listener and writer.

```console
$ ./hack/test-port-forwarding.pl default [nc|socat] [nc|socat]
```

The `nc` command always sets `SO_REUSEPORT` on the listening TCP port.
The `socat` command provides a `reuseport` option that enables `SO_REUSEPORT` on the listening TCP port.

Ref: lima-vm#4160 (comment)
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>

hack/test-port-forwarding.pl: Add a connection timeout option and relax it from 1 second to 3 seconds.

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 3cc7ac2 into lima-vm:master Oct 9, 2025
114 of 121 checks passed
@norio-nomura norio-nomura deleted the portfwd-remove-SO_REUSEPORT branch October 9, 2025 08:51
@norio-nomura
Copy link
Contributor Author

Thanks! 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants