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
parentf54ee715e237709e722a009ae4a3622425f9b8ae (diff)
Allow socket reuse in tableflip
-rw-r--r--NOTICE26
-rw-r--r--changelogs/unreleased/jc-use-SOCKETREUSE.yml5
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--internal/bootstrap/bootstrap.go17
-rw-r--r--internal/bootstrap/bootstrap_test.go18
6 files changed, 42 insertions, 30 deletions
diff --git a/NOTICE b/NOTICE
index 70a54ae4f..2cd65602e 100644
--- a/NOTICE
+++ b/NOTICE
@@ -949,32 +949,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-LICENSE - github.com/pkg/errors
-Copyright (c) 2015, Dave Cheney &lt;dave@cheney.net&gt;
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &#34;AS IS&#34;
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LICENSE - github.com/pmezard/go-difflib/difflib
Copyright (c) 2013, Patrick Mezard
All rights reserved.
diff --git a/changelogs/unreleased/jc-use-SOCKETREUSE.yml b/changelogs/unreleased/jc-use-SOCKETREUSE.yml
new file mode 100644
index 000000000..2111fa9e1
--- /dev/null
+++ b/changelogs/unreleased/jc-use-SOCKETREUSE.yml
@@ -0,0 +1,5 @@
+---
+title: Allow port reuse in tableflip
+merge_request: 2175
+author:
+type: fixed
diff --git a/go.mod b/go.mod
index a9d8e7317..4705185ea 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module gitlab.com/gitlab-org/gitaly
require (
github.com/BurntSushi/toml v0.3.1
github.com/beorn7/perks v1.0.1 // indirect
- github.com/cloudflare/tableflip v0.0.0-20190329062924-8392f1641731
+ github.com/cloudflare/tableflip v1.2.1-0.20200514155827-4baec9811f2b
github.com/getsentry/sentry-go v0.5.1
github.com/golang/protobuf v1.3.2
github.com/google/uuid v1.1.1
diff --git a/go.sum b/go.sum
index ced17a5b1..c3d5bcfdf 100644
--- a/go.sum
+++ b/go.sum
@@ -47,8 +47,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/client9/reopen v1.0.0 h1:8tpLVR74DLpLObrn2KvsyxJY++2iORGR17WLUdSzUws=
github.com/client9/reopen v1.0.0/go.mod h1:caXVCEr+lUtoN1FlsRiOWdfQtdRHIYfcb0ai8qKWtkQ=
-github.com/cloudflare/tableflip v0.0.0-20190329062924-8392f1641731 h1:tvNK3KGRG8h21JyXyKxEjnxsWnbp0+NopDqNrXO5fg0=
-github.com/cloudflare/tableflip v0.0.0-20190329062924-8392f1641731/go.mod h1:erh4dYezoMVbIa52pi7i1Du7+cXOgqNuTamt10qvMoA=
+github.com/cloudflare/tableflip v1.2.1-0.20200514155827-4baec9811f2b h1:PF1TsqplD1wyV3nBSzRHP3teTQFtaWl3jaENrGqZ+lI=
+github.com/cloudflare/tableflip v1.2.1-0.20200514155827-4baec9811f2b/go.mod h1:vhhSlJqV8uUnxGkRSgyvGthfGlkAwJ4UuSV51fSrCQY=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
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