From 08cb93c98f7be3790d51160d64797f35591cc04b Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 13 Mar 2020 22:54:09 +0300 Subject: Add -trimpath to the build script --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 2a696538..81841f7d 100755 --- a/build.sh +++ b/build.sh @@ -44,7 +44,7 @@ build_musl() { echo Packaging "$2" Build bdir=roadrunner-${RR_VERSION}-$1-$2-$3 rm -rf builds/"$bdir" && mkdir -p builds/"$bdir" - CC=musl-gcc GOARCH=amd64 go build -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go + CC=musl-gcc GOARCH=amd64 go build -trimpath -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go mv rr builds/"$bdir" @@ -68,4 +68,4 @@ if [ "$1" == "all" ]; then exit fi -CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go +CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go -- cgit v1.2.3 From 4ae5a7e7213798892d511a7a53ecd148e22ca7f6 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Sat, 14 Mar 2020 00:57:28 +0300 Subject: Fix panic in Serve Add test for the bug Uncomment test in container. It's working properly now --- go.mod | 1 + go.sum | 1 + service/container.go | 7 +++++++ service/container_test.go | 33 +++++++++++++++++---------------- service/gzip/service.go | 5 +++++ service/gzip/service_test.go | 18 ++++++++++++++++++ 6 files changed, 49 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 846a58dd..988a9856 100644 --- a/go.mod +++ b/go.mod @@ -22,4 +22,5 @@ require ( github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a github.com/yookoala/gofast v0.4.0 golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 + golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e ) diff --git a/go.sum b/go.sum index c20056af..183fa45e 100644 --- a/go.sum +++ b/go.sum @@ -271,6 +271,7 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/service/container.go b/service/container.go index 85f63eeb..77a6dfc0 100644 --- a/service/container.go +++ b/service/container.go @@ -166,8 +166,10 @@ func (c *container) Init(cfg Config) error { // Serve all configured services. Non blocking. func (c *container) Serve() error { + var running = 0 for _, e := range c.services { if e.hasStatus(StatusOK) && e.canServe() { + running++ c.log.Debugf("[%s]: started", e.name) go func(e *entry) { e.setStatus(StatusServing) @@ -187,6 +189,11 @@ func (c *container) Serve() error { } } + // simple handler to handle empty configs + if running == 0 { + return nil + } + for fail := range c.errc { if fail.err == errTempFix223 { // if we call stop, then stop all plugins diff --git a/service/container_test.go b/service/container_test.go index 94bc243f..d7ca73a7 100644 --- a/service/container_test.go +++ b/service/container_test.go @@ -302,22 +302,23 @@ func TestContainer_ConfigureTwice(t *testing.T) { assert.Error(t, c.Init(&testCfg{`{"test":"something"}`})) } -//func TestContainer_ServeEmptyContainer(t *testing.T) { -// logger, hook := test.NewNullLogger() -// logger.SetLevel(logrus.DebugLevel) -// -// svc := &testService{ok: true} -// -// c := NewContainer(logger) -// c.Register("test", svc) -// assert.Equal(t, 0, len(hook.Entries)) -// -// go assert.NoError(t, c.Serve()) -// -// time.Sleep(time.Millisecond * 500) -// -// c.Stop() -//} +// bug #276 test +func TestContainer_ServeEmptyContainer(t *testing.T) { + logger, hook := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + svc := &testService{ok: true} + + c := NewContainer(logger) + c.Register("test", svc) + assert.Equal(t, 0, len(hook.Entries)) + + go assert.NoError(t, c.Serve()) + + time.Sleep(time.Millisecond * 500) + + c.Stop() +} func TestContainer_Serve(t *testing.T) { logger, hook := test.NewNullLogger() diff --git a/service/gzip/service.go b/service/gzip/service.go index bb6bcfcd..5ae3ffd5 100644 --- a/service/gzip/service.go +++ b/service/gzip/service.go @@ -1,6 +1,7 @@ package gzip import ( + "errors" "github.com/NYTimes/gziphandler" rrhttp "github.com/spiral/roadrunner/service/http" "net/http" @@ -8,12 +9,16 @@ import ( // ID contains default service name. const ID = "gzip" +var httpNotInitialized = errors.New("http service should be defined properly in config") type Service struct { cfg *Config } func (s *Service) Init(cfg *Config, r *rrhttp.Service) (bool, error) { + if r == nil { + return false, httpNotInitialized + } s.cfg = cfg if !s.cfg.Enable { diff --git a/service/gzip/service_test.go b/service/gzip/service_test.go index 858dbe56..ba14b862 100644 --- a/service/gzip/service_test.go +++ b/service/gzip/service_test.go @@ -47,3 +47,21 @@ func Test_Disabled(t *testing.T) { assert.NotNil(t, s) assert.Equal(t, service.StatusInactive, st) } + +// TEST bug #275 +func Test_Bug275(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(ID, &Service{}) + + assert.Error(t, c.Init(&testCfg{ + httpCfg:"", + gzip: `{"enable":false}`, + })) + + s, st := c.Get(ID) + assert.NotNil(t, s) + assert.Equal(t, service.StatusInactive, st) +} -- cgit v1.2.3 From 5e4c32f90db8ae6de541598304907974762f1673 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Sat, 14 Mar 2020 01:29:59 +0300 Subject: Fix potencial issue in gzip with cfg initialization Add test for bug 275 --- service/gzip/service.go | 9 ++++----- service/gzip/service_test.go | 14 +++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/service/gzip/service.go b/service/gzip/service.go index 5ae3ffd5..231ba4d9 100644 --- a/service/gzip/service.go +++ b/service/gzip/service.go @@ -9,21 +9,20 @@ import ( // ID contains default service name. const ID = "gzip" -var httpNotInitialized = errors.New("http service should be defined properly in config") +var httpNotInitialized = errors.New("http service should be defined properly in config to use gzip") type Service struct { cfg *Config } func (s *Service) Init(cfg *Config, r *rrhttp.Service) (bool, error) { - if r == nil { - return false, httpNotInitialized - } s.cfg = cfg - if !s.cfg.Enable { return false, nil } + if r == nil { + return false, httpNotInitialized + } r.AddMiddleware(s.middleware) diff --git a/service/gzip/service_test.go b/service/gzip/service_test.go index ba14b862..9a62a08b 100644 --- a/service/gzip/service_test.go +++ b/service/gzip/service_test.go @@ -13,7 +13,6 @@ import ( type testCfg struct { gzip string httpCfg string - //static string target string } @@ -31,15 +30,20 @@ func (cfg *testCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.target), out) } - func Test_Disabled(t *testing.T) { logger, _ := test.NewNullLogger() logger.SetLevel(logrus.DebugLevel) c := service.NewContainer(logger) - c.Register(ID, &Service{}) + c.Register(ID, &Service{cfg: &Config{Enable: true}}) assert.NoError(t, c.Init(&testCfg{ + httpCfg: `{ + "address": ":6029", + "workers":{ + "command": "php ../../tests/http/client.php echo pipes", + } + }`, gzip: `{"enable":false}`, })) @@ -57,8 +61,8 @@ func Test_Bug275(t *testing.T) { c.Register(ID, &Service{}) assert.Error(t, c.Init(&testCfg{ - httpCfg:"", - gzip: `{"enable":false}`, + httpCfg: "", + gzip: `{"enable":true}`, })) s, st := c.Get(ID) -- cgit v1.2.3