From 49fde946ac82a0dde2b981b391d8d94ab3aa07d8 Mon Sep 17 00:00:00 2001 From: Maxim Merzhanov Date: Wed, 26 Feb 2020 17:48:46 +0300 Subject: [PATCH] configure leader ws client ConnectionReadLimit --- CHANGELOG.md | 3 +++ cluster/leader_client.go | 17 ++++++++++++----- main.go | 22 ++++++++++++---------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3dff0b..9ac8adb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v2.1.2 +* leader ws client ConnectionReadLimit is now configured by WS.WsConnectionReadLimitKB config param and defaults to 4 MB + ### v2.1.1 * update to new endpoint descriptor struct with extra fields introduced in isp-lib v2.1.0 diff --git a/cluster/leader_client.go b/cluster/leader_client.go index 66ef2a3..20b4a5a 100644 --- a/cluster/leader_client.go +++ b/cluster/leader_client.go @@ -3,6 +3,11 @@ package cluster import ( "context" "fmt" + "net" + "net/http" + "net/url" + "time" + "github.com/cenkalti/backoff" etp "github.com/integration-system/isp-etp-go/client" "github.com/integration-system/isp-lib/config" @@ -11,10 +16,11 @@ import ( log "github.com/integration-system/isp-log" "isp-config-service/codes" "isp-config-service/conf" - "net" - "net/http" - "net/url" - "time" +) + +var ( + // Set from config in main + WsConnectionReadLimit int64 ) type SocketLeaderClient struct { @@ -63,7 +69,8 @@ func (c *SocketLeaderClient) Close() { func NewSocketLeaderClient(address string, leaderDisconnectionCallback func()) *SocketLeaderClient { etpConfig := etp.Config{ - HttpClient: http.DefaultClient, + HttpClient: http.DefaultClient, + ConnectionReadLimit: WsConnectionReadLimit, } client := etp.NewClient(etpConfig) leaderClient := &SocketLeaderClient{ diff --git a/main.go b/main.go index a751cd0..4a4caf5 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,10 @@ package main import ( "context" "fmt" + "net" + "net/http" + "os" + "github.com/integration-system/isp-etp-go" "github.com/integration-system/isp-lib/backend" "github.com/integration-system/isp-lib/bootstrap" @@ -24,9 +28,6 @@ import ( "isp-config-service/store" "isp-config-service/store/state" "isp-config-service/subs" - "net" - "net/http" - "os" ) const ( @@ -36,7 +37,6 @@ const ( var ( version = "0.1.0" - date = "undefined" shutdownChan = make(chan struct{}) muxer mux.Mux @@ -81,6 +81,12 @@ func main() { Address: address, } + connectionReadLimit := defaultWsConnectionReadLimit + if cfg.WS.WsConnectionReadLimitKB > 0 { + connectionReadLimit = cfg.WS.WsConnectionReadLimitKB << 10 + } + cluster.WsConnectionReadLimit = connectionReadLimit + model.DbClient.ReceiveConfiguration(cfg.Database) httpListener, raftListener, err := initMultiplexer(cfg.WS.Rest) @@ -89,7 +95,7 @@ func main() { } _, raftStore := initRaft(raftListener, cfg.Cluster, declaration) - initWebsocket(ctx, cfg.WS.WsConnectionReadLimitKB, httpListener, raftStore) + initWebsocket(ctx, connectionReadLimit, httpListener, raftStore) initGrpc(cfg.WS.Grpc, raftStore) defer goodbye.Exit(ctx, -1) @@ -121,11 +127,7 @@ func initMultiplexer(addressConfiguration structure.AddressConfiguration) (net.L return httpListener, raftListener, nil } -func initWebsocket(ctx context.Context, wsConnectionReadLimitKB int64, listener net.Listener, raftStore *store.Store) { - connectionReadLimit := defaultWsConnectionReadLimit - if wsConnectionReadLimitKB > 0 { - connectionReadLimit = wsConnectionReadLimitKB << 10 - } +func initWebsocket(ctx context.Context, connectionReadLimit int64, listener net.Listener, raftStore *store.Store) { etpConfig := etp.ServerConfig{ InsecureSkipVerify: true, ConnectionReadLimit: connectionReadLimit,