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

Reuse unix sockets (UDS) and don't try to serve HTTP/3 over UDS #5063

Merged
merged 5 commits into from
Sep 21, 2022

Conversation

mholt
Copy link
Member

@mholt mholt commented Sep 21, 2022

This PR hopefully fixes #5056 - any use of Unix domain sockets (UDS) cause errors now because somehow I missed that SO_REUSEPORT doesn't apply to UDS, even though it's a socket too.

My testing didn't catch this before because I didn't attempt to do a config reload with unix sockets specifically.


To test this, I created a simple server:

localhost

bind unix//home/matt/Desktop/test.sock
respond "Hello world!"

(I also enabled debug mode for my tests, but not required.)

I also added time.Sleep(1 * time.Second) to the static_response handler (respond directive) between writing headers and the body, to simulate a slow request-response. (I also repeated the tests without this sleep successfully.)

I started the server, then I ran this bash loop:

for i in {1..100000}; do
  curl -v --unix-socket ~/Desktop/test.sock "https://localhost/"
  sleep 0.001
done

to get "Hello world".

At the same time I ran this loop:

for i in {1..10000}; do
  curl -v "http://localhost:2019/load" -H "Content-Type: text/caddyfile" -H "Cache-Control: must-revalidate" --data-binary @Caddyfile
  sleep 0.01
done

to rapidly change the config. This should put the reload code (and unix socket reuse) through its paces.

I observed 0 errors, 0 failed requests, and 0 resource leaks (I used localhost:2019/debug/pprof to watch goroutines and I also used the system monitor to measure memory use).


For HTTP/3 support on UDS, we having an upstream discussion: quic-go/quic-go#3560

I don't expect the tests to pass for all platforms yet. I just found out Go has a new unix build tag that I'm trying out.

@mholt mholt added the bug 🐞 Something isn't working label Sep 21, 2022
@mholt mholt added this to the v2.6.1 milestone Sep 21, 2022
@mholt mholt self-assigned this Sep 21, 2022
@mholt
Copy link
Member Author

mholt commented Sep 21, 2022

Ahhhh dangit, unix build tag was only added in Go 1.19. 😢

@mholt mholt merged commit 1426c97 into master Sep 21, 2022
@mholt mholt deleted the unixsockets branch September 21, 2022 18:55
@mholt mholt modified the milestones: v2.6.1, v2.6.2 Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config reload fails when admin endpoint is a socket
1 participant