Skip to content

Commit

Permalink
Remove gracehttp and force reuseport on listening sockets
Browse files Browse the repository at this point in the history
* Remove gracehttp as it is no longer supported (repo was archives)
  and it was reported to be broken (#552)
* Force reuseport on listening sockets. That would allow to start
  multiple carbonapi binaries
  • Loading branch information
Civil committed Feb 28, 2021
1 parent 074b1cf commit 0291430
Show file tree
Hide file tree
Showing 34 changed files with 60 additions and 2,379 deletions.
11 changes: 11 additions & 0 deletions cmd/carbonapi/helper/reuseport_default.go
@@ -0,0 +1,11 @@
// +build !linux

package helper

import (
"syscall"
)

func ReusePort(network, address string, conn syscall.RawConn) error {
return nil
}
13 changes: 13 additions & 0 deletions cmd/carbonapi/helper/reuseport_linux.go
@@ -0,0 +1,13 @@
package helper

import (
"syscall"

"golang.org/x/sys/unix"
)

func ReusePort(network, address string, conn syscall.RawConn) error {
return conn.Control(func(descriptor uintptr) {
syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1)
})
}
28 changes: 23 additions & 5 deletions cmd/carbonapi/main.go
@@ -1,19 +1,21 @@
package main

import (
"context"
"expvar"
"flag"
"log"
"net"
"net/http"
"net/http/pprof"
"sync"

"github.com/facebookgo/grace/gracehttp"
"github.com/gorilla/handlers"
"github.com/lomik/zapwriter"
"go.uber.org/zap"

"github.com/go-graphite/carbonapi/cmd/carbonapi/config"
"github.com/go-graphite/carbonapi/cmd/carbonapi/helper"
carbonapiHttp "github.com/go-graphite/carbonapi/cmd/carbonapi/http"
"github.com/go-graphite/carbonapi/internal/dns"
)
Expand Down Expand Up @@ -77,10 +79,18 @@ func main() {
}
wg.Add(1)
go func(listen config.Listener) {
err = gracehttp.Serve(&http.Server{
l := &net.ListenConfig{Control: helper.ReusePort}
s := &http.Server{
Addr: listen.Address,
Handler: handler,
})
}
listener, err := l.Listen(context.Background(), "tcp", listen.Address)
if err != nil {
logger.Fatal("failed to start http server",
zap.Error(err),
)
}
err = s.Serve(listener)

if err != nil {
logger.Fatal("failed to start http server",
Expand All @@ -101,10 +111,18 @@ func main() {
for _, listener := range config.Config.Listeners {
wg.Add(1)
go func(listen config.Listener) {
err = gracehttp.Serve(&http.Server{
l := &net.ListenConfig{Control: helper.ReusePort}
s := &http.Server{
Addr: listen.Address,
Handler: handler,
})
}
listener, err := l.Listen(context.Background(), "tcp", listen.Address)
if err != nil {
logger.Fatal("failed to start http server",
zap.Error(err),
)
}
err = s.Serve(listener)

if err != nil {
logger.Fatal("failed to start http server",
Expand Down
17 changes: 9 additions & 8 deletions cmd/carbonzipper/main.go
Expand Up @@ -20,18 +20,18 @@ import (
"github.com/ansel1/merry"

"github.com/dgryski/httputil"
"github.com/facebookgo/grace/gracehttp"
"github.com/facebookgo/pidfile"
protov2 "github.com/go-graphite/protocol/carbonapi_v2_pb"
protov3 "github.com/go-graphite/protocol/carbonapi_v3_pb"
"github.com/lomik/zapwriter"
"github.com/spf13/viper"

"github.com/go-graphite/carbonapi/intervalset"
"github.com/go-graphite/carbonapi/mstats"
util "github.com/go-graphite/carbonapi/util/ctx"
"github.com/go-graphite/carbonapi/zipper"
zipperConfig "github.com/go-graphite/carbonapi/zipper/config"
"github.com/go-graphite/carbonapi/zipper/types"
protov2 "github.com/go-graphite/protocol/carbonapi_v2_pb"
protov3 "github.com/go-graphite/protocol/carbonapi_v3_pb"
"github.com/lomik/zapwriter"
"github.com/spf13/viper"

pickle "github.com/lomik/og-rek"
"github.com/peterbourgon/g2g"
Expand Down Expand Up @@ -812,13 +812,14 @@ func main() {
go srv.serve()
}

err = gracehttp.Serve(&http.Server{
srv := &http.Server{
Addr: config.Listen,
Handler: nil,
})
}
err = srv.ListenAndServe()

if err != nil {
logger.Fatal("error during gracehttp.Serve()",
logger.Fatal("error during starting web server",
zap.Error(err),
)
}
Expand Down
9 changes: 1 addition & 8 deletions go.mod
Expand Up @@ -14,15 +14,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/evmar/gocairo v0.0.0-20160222165215-ddd30f837497
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 // indirect
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2 // indirect
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/go-graphite/protocol v0.4.3
github.com/golang/protobuf v1.4.0
github.com/gorilla/handlers v1.4.2
Expand All @@ -41,6 +33,7 @@ require (
github.com/valyala/fastjson v1.6.1
github.com/wangjohn/quickselect v0.0.0-20161129230411-ed8402a42d5f
go.uber.org/zap v1.16.0
golang.org/x/sys v0.0.0-20190412213103-97732733099d
gonum.org/v1/gonum v0.7.0
google.golang.org/grpc v1.29.1
gopkg.in/yaml.v2 v2.2.8
Expand Down
18 changes: 0 additions & 18 deletions go.sum
Expand Up @@ -47,24 +47,8 @@ github.com/evmar/gocairo v0.0.0-20160222165215-ddd30f837497 h1:DIQ8EvZ8OjuPNfcV4
github.com/evmar/gocairo v0.0.0-20160222165215-ddd30f837497/go.mod h1:YXKUYPSqs+jDG8mvexHN2uTik4PKwg2B0WK9itQ0VrE=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 h1:BBso6MBKW8ncyZLv37o+KNyy0HrrHgfnOaGQC2qvN+A=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 h1:wWke/RUCl7VRjQhwPlR/v0glZXNYzBHdNUzf/Am2Nmg=
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9/go.mod h1:uPmAp6Sws4L7+Q/OokbWDAK1ibXYhB3PXFP1kol5hPg=
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 h1:mOp33BLbcbJ8fvTAmZacbBiOASfxN+MLcLxymZCIrGE=
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434/go.mod h1:KigFdumBXUPSwzLDbeuzyt0elrL7+CP7TKuhrhT4bcU=
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2 h1:nXeeRHmgNgjLxi+7dY9l9aDvSS1uwVlNLqUWIY4Ath0=
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2/go.mod h1:TUV/fX3XrTtBQb5+ttSUJzcFgLNpILONFTKmBuk5RSw=
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868 h1:KZ75X3ZCl6yy4jg9R1ziYoCZFDBRqildm+fGComWU7U=
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868/go.mod h1:3Hzo46xzfVpIdv4lJw7YBp9fUJ7HpUgbjH1fFDgy4qM=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 h1:0YtRCqIZs2+Tz49QuH6cJVw/IFqzo39gEqZ0iYLxD2M=
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4/go.mod h1:vsJz7uE339KUCpBXx3JAJzSRH7Uk4iGGyJzR529qDIA=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -217,8 +201,6 @@ go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKY
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
21 changes: 0 additions & 21 deletions vendor/github.com/facebookgo/clock/LICENSE

This file was deleted.

104 changes: 0 additions & 104 deletions vendor/github.com/facebookgo/clock/README.md

This file was deleted.

0 comments on commit 0291430

Please sign in to comment.