Skip to content

Commit

Permalink
fix: enable SO_REUSEPORT in listener config
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Feb 6, 2025
1 parent 8078cdc commit b604b8b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/serve_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/http"
"sync"
"syscall"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -105,7 +106,18 @@ func serve(ctx context.Context) {
}
}()

if err := httpSrv.ListenAndServe(); err != http.ErrServerClosed {
lc := net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1)

Check failure on line 112 in cmd/serve_cmd.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

undefined: syscall.SO_REUSEPORT
})
},
}
listener, err := lc.Listen(ctx, "tcp", addr)
if err != nil {
log.WithError(err).Fatal("http server listen failed")
}
if err := httpSrv.Serve(listener); err != nil {
log.WithError(err).Fatal("http server serve failed")
}
}

0 comments on commit b604b8b

Please sign in to comment.