From 9c2124d14cbcd7646f38d5c2ab5ba66df632d9fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 15:38:38 +0400 Subject: [PATCH 1/4] Bump google.golang.org/protobuf from 1.35.2 to 1.36.0 (#2345) Bumps google.golang.org/protobuf from 1.35.2 to 1.36.0. --- updated-dependencies: - dependency-name: google.golang.org/protobuf dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 74dd3ef792..65aad984d6 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( go.uber.org/zap v1.27.0 golang.org/x/crypto v0.31.0 google.golang.org/grpc v1.69.0 - google.golang.org/protobuf v1.35.2 + google.golang.org/protobuf v1.36.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index d49367b792..011bca7ad8 100644 --- a/go.sum +++ b/go.sum @@ -820,8 +820,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= -google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 6918b15850e1692efd1f878db54bca80985db815 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 15:52:44 +0400 Subject: [PATCH 2/4] Bump google.golang.org/grpc from 1.69.0 to 1.69.2 (#2344) Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.69.0 to 1.69.2. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.69.0...v1.69.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: Kirill Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kirill --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 65aad984d6..de86f9eb0b 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( go.uber.org/mock v0.5.0 go.uber.org/zap v1.27.0 golang.org/x/crypto v0.31.0 - google.golang.org/grpc v1.69.0 + google.golang.org/grpc v1.69.2 google.golang.org/protobuf v1.36.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 011bca7ad8..be87c71c45 100644 --- a/go.sum +++ b/go.sum @@ -809,8 +809,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.69.0 h1:quSiOM1GJPmPH5XtU+BCoVXcDVJJAzNcoyfC2cCjGkI= -google.golang.org/grpc v1.69.0/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4= +google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU= +google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= From fce50781632339d60d45c308121c4501b3724d1b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:23:43 +0400 Subject: [PATCH 3/4] Bump github.com/bits-and-blooms/bitset from 1.19.1 to 1.20.0 (#2343) Bumps [github.com/bits-and-blooms/bitset](https://github.com/bits-and-blooms/bitset) from 1.19.1 to 1.20.0. - [Release notes](https://github.com/bits-and-blooms/bitset/releases) - [Commits](https://github.com/bits-and-blooms/bitset/compare/v1.19.1...v1.20.0) --- updated-dependencies: - dependency-name: github.com/bits-and-blooms/bitset dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index de86f9eb0b..f2280b96ae 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ go 1.23.4 require ( github.com/Masterminds/semver/v3 v3.3.1 github.com/NethermindEth/cairo-vm-go v0.0.0-20241022093807-167daddfd4a4 - github.com/bits-and-blooms/bitset v1.19.1 + github.com/bits-and-blooms/bitset v1.20.0 github.com/bits-and-blooms/bloom/v3 v3.7.0 github.com/cockroachdb/pebble v1.1.2 github.com/coder/websocket v1.8.12 diff --git a/go.sum b/go.sum index be87c71c45..2e138d5764 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= -github.com/bits-and-blooms/bitset v1.19.1 h1:mv2yVhy96D2CuskLPXnc58oJNMs5PCWjAZuyYU0p12M= -github.com/bits-and-blooms/bitset v1.19.1/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3MdfoPyRVU= +github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bits-and-blooms/bloom/v3 v3.7.0 h1:VfknkqV4xI+PsaDIsoHueyxVDZrfvMn56jeWUzvzdls= github.com/bits-and-blooms/bloom/v3 v3.7.0/go.mod h1:VKlUSvp0lFIYqxJjzdnSsZEw4iHb1kOL2tfHTgyJBHg= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= From 81262fd52656fd9ac954b2178f0daff60c327f1d Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 23 Dec 2024 18:44:44 +0400 Subject: [PATCH 4/4] Websocket shutdown logic (#2277) --- jsonrpc/websocket.go | 19 +++++++++++++++++-- jsonrpc/websocket_test.go | 2 +- node/http.go | 15 +++++++++++++-- rpc/events_test.go | 2 +- rpc/subscriptions.go | 1 - 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/jsonrpc/websocket.go b/jsonrpc/websocket.go index b3e436703a..2c1e207a54 100644 --- a/jsonrpc/websocket.go +++ b/jsonrpc/websocket.go @@ -18,14 +18,17 @@ type Websocket struct { log utils.SimpleLogger connParams *WebsocketConnParams listener NewRequestListener + + shutdown <-chan struct{} } -func NewWebsocket(rpc *Server, log utils.SimpleLogger) *Websocket { +func NewWebsocket(rpc *Server, shutdown <-chan struct{}, log utils.SimpleLogger) *Websocket { ws := &Websocket{ rpc: rpc, log: log, connParams: DefaultWebsocketConnParams(), listener: &SelectiveListener{}, + shutdown: shutdown, } return ws @@ -54,7 +57,19 @@ func (ws *Websocket) ServeHTTP(w http.ResponseWriter, r *http.Request) { // TODO include connection information, such as the remote address, in the logs. - wsc := newWebsocketConn(r.Context(), conn, ws.connParams) + ctx, cancel := context.WithCancel(r.Context()) + defer cancel() + go func() { + select { + case <-ws.shutdown: + cancel() + case <-ctx.Done(): + // in case websocket connection is closed and server is not in shutdown mode + // we need to release this goroutine from waiting + } + }() + + wsc := newWebsocketConn(ctx, conn, ws.connParams) for { _, wsc.r, err = wsc.conn.Reader(wsc.ctx) diff --git a/jsonrpc/websocket_test.go b/jsonrpc/websocket_test.go index 9baf704ae9..4f60377c02 100644 --- a/jsonrpc/websocket_test.go +++ b/jsonrpc/websocket_test.go @@ -20,7 +20,7 @@ func testConnection(t *testing.T, ctx context.Context, method jsonrpc.Method, li require.NoError(t, rpc.RegisterMethods(method)) // Server - srv := httptest.NewServer(jsonrpc.NewWebsocket(rpc, utils.NewNopZapLogger())) + srv := httptest.NewServer(jsonrpc.NewWebsocket(rpc, nil, utils.NewNopZapLogger())) // Client conn, resp, err := websocket.Dial(ctx, srv.URL, nil) //nolint:bodyclose // websocket package closes resp.Body for us. diff --git a/node/http.go b/node/http.go index 4226564b0a..89a6db60fc 100644 --- a/node/http.go +++ b/node/http.go @@ -52,6 +52,10 @@ func (h *httpService) Run(ctx context.Context) error { } } +func (h *httpService) registerOnShutdown(f func()) { + h.srv.RegisterOnShutdown(f) +} + func makeHTTPService(host string, port uint16, handler http.Handler) *httpService { portStr := strconv.FormatUint(uint64(port), 10) return &httpService{ @@ -108,9 +112,11 @@ func makeRPCOverWebsocket(host string, port uint16, servers map[string]*jsonrpc. listener = makeWSMetrics() } + shutdown := make(chan struct{}) + mux := http.NewServeMux() for path, server := range servers { - wsHandler := jsonrpc.NewWebsocket(server, log) + wsHandler := jsonrpc.NewWebsocket(server, shutdown, log) if listener != nil { wsHandler = wsHandler.WithListener(listener) } @@ -124,7 +130,12 @@ func makeRPCOverWebsocket(host string, port uint16, servers map[string]*jsonrpc. if corsEnabled { handler = cors.Default().Handler(handler) } - return makeHTTPService(host, port, handler) + + httpServ := makeHTTPService(host, port, handler) + httpServ.registerOnShutdown(func() { + close(shutdown) + }) + return httpServ } func makeMetrics(host string, port uint16) *httpService { diff --git a/rpc/events_test.go b/rpc/events_test.go index c2f1417791..6655b6166e 100644 --- a/rpc/events_test.go +++ b/rpc/events_test.go @@ -351,7 +351,7 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) { Params: []jsonrpc.Parameter{{Name: "id"}}, Handler: handler.Unsubscribe, })) - ws := jsonrpc.NewWebsocket(server, log) + ws := jsonrpc.NewWebsocket(server, nil, log) httpSrv := httptest.NewServer(ws) conn1, _, err := websocket.Dial(ctx, httpSrv.URL, nil) require.NoError(t, err) diff --git a/rpc/subscriptions.go b/rpc/subscriptions.go index b049c6ce0d..5edf1bcfbb 100644 --- a/rpc/subscriptions.go +++ b/rpc/subscriptions.go @@ -90,7 +90,6 @@ func (h *Handler) SubscribeEvents(ctx context.Context, fromAddr *felt.Felt, keys case <-subscriptionCtx.Done(): return case header := <-headerSub.Recv(): - h.processEvents(subscriptionCtx, w, id, header.Number, header.Number, fromAddr, keys) } }