From 3f8e03eda413852eb78cbc0d5ea89a9385ff387b Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Thu, 23 Jan 2020 17:46:39 +0300 Subject: [PATCH] fix init http --- .version | 2 +- CHANGELOG.md | 2 ++ main.go | 5 +---- server/http.go | 19 ++++++++++++++++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.version b/.version index 73462a5..f225a78 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.5.1 +2.5.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 90fef78..f03f964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 2.5.2 +* fix init http ## 2.5.1 * fix code response when doesn't match user id * fix config reload diff --git a/main.go b/main.go index a53fa4e..46cbac1 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "github.com/integration-system/go-cmp/cmp" "github.com/integration-system/isp-lib/bootstrap" "github.com/integration-system/isp-lib/config" "github.com/integration-system/isp-lib/config/schema" @@ -71,9 +70,7 @@ func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) { metric.InitHttpServer(remoteConfig.Metrics) service.Metrics.Init() - if !cmp.Equal(remoteConfig.HttpSetting, oldRemoteConfig.HttpSetting) { - server.Http.Init(remoteConfig.HttpSetting.GetMaxRequestBodySize()) - } + server.Http.Init(remoteConfig.HttpSetting, oldRemoteConfig.HttpSetting) } func socketConfiguration(cfg interface{}) structure.SocketConfiguration { diff --git a/server/http.go b/server/http.go index 1d90510..5c4a80d 100644 --- a/server/http.go +++ b/server/http.go @@ -1,6 +1,7 @@ package server import ( + "github.com/integration-system/go-cmp/cmp" "github.com/integration-system/isp-lib/config" log "github.com/integration-system/isp-log" "github.com/valyala/fasthttp" @@ -14,12 +15,24 @@ import ( var Http = &httpSrv{mx: sync.Mutex{}} type httpSrv struct { - srv *fasthttp.Server - mx sync.Mutex + working bool + srv *fasthttp.Server + mx sync.Mutex } -func (s *httpSrv) Init(MaxRequestBodySize int64) { +func (s *httpSrv) Init(new, old conf.HttpSetting) { + if s.working { + if !cmp.Equal(new, old) { + s.run(new.GetMaxRequestBodySize()) + } + } else { + s.run(new.GetMaxRequestBodySize()) + } +} + +func (s *httpSrv) run(MaxRequestBodySize int64) { s.mx.Lock() + s.working = true if s.srv != nil { if err := s.srv.Shutdown(); err != nil { log.Warn(log_code.WarnHttpServerShutdown, err)