Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2020-05-14 23:27:22 +0300
committerJohn Cai <jcai@gitlab.com>2020-05-15 01:54:58 +0300
commit5c9d4ecd511bf992e2ea7ba3374abf961b85eacb (patch)
treec24c51cc0f294d94c826cea67615aaafef046ada /internal/bootstrap
parentf54ee715e237709e722a009ae4a3622425f9b8ae (diff)
Allow socket reuse in tableflip
Diffstat (limited to 'internal/bootstrap')
-rw-r--r--internal/bootstrap/bootstrap.go17
-rw-r--r--internal/bootstrap/bootstrap_test.go18
2 files changed, 34 insertions, 1 deletions
diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go
index 214487e63..839906003 100644
--- a/internal/bootstrap/bootstrap.go
+++ b/internal/bootstrap/bootstrap.go
@@ -11,6 +11,7 @@ import (
"github.com/cloudflare/tableflip"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly/internal/config"
+ "golang.org/x/sys/unix"
)
const (
@@ -67,7 +68,21 @@ func New() (*Bootstrap, error) {
_, upgradesEnabled := os.LookupEnv(EnvUpgradesEnabled)
// PIDFile is optional, if provided tableflip will keep it updated
- upg, err := tableflip.New(tableflip.Options{PIDFile: pidFile})
+ upg, err := tableflip.New(tableflip.Options{
+ PIDFile: pidFile,
+ ListenConfig: &net.ListenConfig{
+ Control: func(network, address string, c syscall.RawConn) error {
+ var opErr error
+ err := c.Control(func(fd uintptr) {
+ opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
+ })
+ if err != nil {
+ return err
+ }
+ return opErr
+ },
+ },
+ })
if err != nil {
return nil, err
}
diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go
index 15c43fba5..16e85fe65 100644
--- a/internal/bootstrap/bootstrap_test.go
+++ b/internal/bootstrap/bootstrap_test.go
@@ -201,6 +201,24 @@ func TestGracefulTermination(t *testing.T) {
require.Contains(t, err.Error(), "completed")
}
+func TestPortReuse(t *testing.T) {
+ var addr string
+
+ b, err := New()
+ require.NoError(t, err)
+
+ l, err := b.listen("tcp", "0.0.0.0:")
+ require.NoError(t, err, "failed to bind")
+
+ addr = l.Addr().String()
+ _, port, err := net.SplitHostPort(addr)
+ require.NoError(t, err)
+
+ l, err = b.listen("tcp", "0.0.0.0:"+port)
+ require.NoError(t, err, "failed to bind")
+ require.NoError(t, l.Close())
+}
+
func testGracefulUpdate(t *testing.T, server *testServer, b *Bootstrap, waitTimeout time.Duration, duringGracePeriodCallback func()) error {
defer func(oldVal time.Duration) {
config.Config.GracefulRestartTimeout = oldVal