uNetworking / uNetworking/uSockets
Server fails to bind localhost in container
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 307
- PR merge metrics
- No merged PRs in 30d
Description
From https://github.com/oven-sh/bun/issues/5315
Reproduce
- Edit
examples/http_server.c
change to bind localhost:3000
struct us_listen_socket_t *listen_socket = us_socket_context_listen(SSL, http_context, "localhost", 3000, 0, sizeof(struct http_socket));
- Create a container using the
debian:sid-slimimage and then run thehttp_server. (docker has not been configured for IPv6 stack)
root@5b4095ebc3eb:/tmp/uSockets# ./http_server
Failed to listen!
root@5b4095ebc3eb:/tmp/uSockets# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 5b4095ebc3eb
root@5b4095ebc3eb:/tmp/uSockets# vim /etc/hosts # Remove `::1 localhost ip6-localhost ip6-loopback`
root@5b4095ebc3eb:/tmp/uSockets# ./http_server # works now
Listening on port 3000...
^C
The server fails to bind, but if you remove ::1 from /etc/hosts, it starts successfully. It binds 127.0.0.1 now.
Regarding why there is still ::1 record present in the container even though IPv6 is not configured, please see https://github.com/moby/moby/issues/35954
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with examples/http_server.c at the us_socket_context_listen call and reproduce ./http_server in a debian:sid-slim container with the shown /etc/hosts entries and IPv6 unavailable. Trace the localhost resolution and bind path; done when localhost:3000 starts successfully without removing the ::1 entry, while preserving the existing IPv4 behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, docker
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100