From 2beb1d4b96bb2b727aad769ca231e19139d10418 Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Fri, 21 Jul 2023 17:45:57 +0530 Subject: [PATCH 1/9] improve test helper func to setup web socket conn --- dot/rpc/subscription/helpers_test.go | 11 +++++- subscription_panic_log.txt | 51 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 subscription_panic_log.txt diff --git a/dot/rpc/subscription/helpers_test.go b/dot/rpc/subscription/helpers_test.go index 82c54d61cd..9e24f14027 100644 --- a/dot/rpc/subscription/helpers_test.go +++ b/dot/rpc/subscription/helpers_test.go @@ -22,6 +22,9 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { CheckOrigin: func(r *http.Request) bool { return true }, } + // Use a channel to notify when the WebSocket connection is ready + connReady := make(chan struct{}) + h := func(w http.ResponseWriter, r *http.Request) { c, err := up.Upgrade(w, r, nil) if err != nil { @@ -30,6 +33,9 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { } wskt.Wsconn = c + + // Notify that the WebSocket connection is ready + close(connReady) } server := httptest.NewServer(http.HandlerFunc(h)) @@ -38,9 +44,12 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { wsURL := "ws" + strings.TrimPrefix(server.URL, "http") ws, r, err := websocket.DefaultDialer.Dial(wsURL, nil) defer r.Body.Close() - require.NoError(t, err) + // Wait for the WebSocket connection to be ready before proceeding + <-connReady + require.NotNil(t, wskt.Wsconn) + cancel := func() { server.Close() ws.Close() diff --git a/subscription_panic_log.txt b/subscription_panic_log.txt new file mode 100644 index 0000000000..58b21eee54 --- /dev/null +++ b/subscription_panic_log.txt @@ -0,0 +1,51 @@ +2023-07-22T10:45:40.0738572Z 2023-07-22T10:45:40Z INFO +2023-07-22T10:45:40.0740174Z =========== +2023-07-22T10:45:40.0741115Z c=>0xc00042a120 | c.Wsconn=>0x0 +2023-07-22T10:45:40.0741520Z =========== +2023-07-22T10:45:40.0741693Z pkg=rpc/subscription +2023-07-22T10:45:40.0742185Z 2023-07-22T10:45:40Z ERROR +2023-07-22T10:45:40.0742291Z +2023-07-22T10:45:40.0743984Z msg => {Jsonrpc:2.0 Method:state_storage Params:{Result:{Changes:[[0x6b6579 0x76616c7565]] Block:0x0000000000000000000000000000000000000000000000000000000000000000} SubscriptionID:0}} +2023-07-22T10:45:40.0744225Z +2023-07-22T10:45:40.0744415Z pkg=rpc/subscription +--- FAIL: TestStorageObserver_Update (0.00s) +2023-07-22T10:45:40.0744945Z panic: runtime error: invalid memory address or nil pointer dereference +2023-07-22T10:45:40.0745334Z panic: runtime error: invalid memory address or nil pointer dereference [recovered] +2023-07-22T10:45:40.0745647Z panic: runtime error: invalid memory address or nil pointer dereference +2023-07-22T10:45:40.0746014Z [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xf2edeb] +2023-07-22T10:45:40.0746151Z +2023-07-22T10:45:40.0788776Z goroutine 69 [running]: +2023-07-22T10:45:40.0789530Z testing.tRunner.func1.2({0x105ce20, 0x1ba2f20}) +2023-07-22T10:45:40.0792464Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1526 +0x24e +2023-07-22T10:45:40.0792731Z testing.tRunner.func1() +2023-07-22T10:45:40.0794753Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1529 +0x39f + + +2023-07-22T10:45:40.0796264Z panic({0x105ce20, 0x1ba2f20}) +2023-07-22T10:45:40.0797775Z /opt/hostedtoolcache/go/1.20.6/x64/src/runtime/panic.go:884 +0x213 +2023-07-22T10:45:40.0799266Z github.com/gorilla/websocket.(*Conn).Close(...) +2023-07-22T10:45:40.0800820Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:345 +2023-07-22T10:45:40.0802337Z github.com/ChainSafe/gossamer/dot/rpc/subscription.setupWSConn.func3() +2023-07-22T10:45:40.0804075Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/helpers_test.go:48 +0x4b + + +2023-07-22T10:45:40.0805589Z panic({0x105ce20, 0x1ba2f20}) +2023-07-22T10:45:40.0807069Z /opt/hostedtoolcache/go/1.20.6/x64/src/runtime/panic.go:884 +0x213 +2023-07-22T10:45:40.0808568Z github.com/gorilla/websocket.(*Conn).beginMessage(0x0, 0xc0000d25a0, 0x1) +2023-07-22T10:45:40.0810088Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:479 +0x27 +2023-07-22T10:45:40.0811567Z github.com/gorilla/websocket.(*Conn).NextWriter(0x0, 0x1) +2023-07-22T10:45:40.0813087Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:520 +0x45 +2023-07-22T10:45:40.0814632Z github.com/gorilla/websocket.(*Conn).WriteJSON(0xc00037e150?, {0x10e79e0, 0xc0000cea00}) +2023-07-22T10:45:40.0816162Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/json.go:24 +0x45 +2023-07-22T10:45:40.0817675Z github.com/ChainSafe/gossamer/dot/rpc/subscription.(*WSConn).safeSend(0xc00042a120, {0x10e79e0, 0xc0000cea00}) +2023-07-22T10:45:40.0819325Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/websocket.go:414 +0x186 +2023-07-22T10:45:40.0820868Z github.com/ChainSafe/gossamer/dot/rpc/subscription.(*StorageObserver).Update(0xc000153e48, 0xc000153f20) +2023-07-22T10:45:40.0822480Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/listeners.go:83 +0x426 +2023-07-22T10:45:40.0824185Z github.com/ChainSafe/gossamer/dot/rpc/subscription.TestStorageObserver_Update(0x40f559?) +2023-07-22T10:45:40.0825924Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/listeners_integration_test.go:67 +0x4f3 +2023-07-22T10:45:40.0827414Z testing.tRunner(0xc0000d4820, 0x12ffa40) +2023-07-22T10:45:40.0828572Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1576 +0x10b +2023-07-22T10:45:40.0828765Z created by testing.(*T).Run +2023-07-22T10:45:40.0829031Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1629 +0x3ea +2023-07-22T10:45:40.0829395Z FAIL github.com/ChainSafe/gossamer/dot/rpc/subscription 0.017s +2023-07-22T10:45:40.0831211Z FAIL \ No newline at end of file From 6aeea8334f5be0c41ae4c7b449d0cf3d033da222 Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Sun, 23 Jul 2023 01:03:45 +0530 Subject: [PATCH 2/9] clean up --- subscription_panic_log.txt | 51 -------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 subscription_panic_log.txt diff --git a/subscription_panic_log.txt b/subscription_panic_log.txt deleted file mode 100644 index 58b21eee54..0000000000 --- a/subscription_panic_log.txt +++ /dev/null @@ -1,51 +0,0 @@ -2023-07-22T10:45:40.0738572Z 2023-07-22T10:45:40Z INFO -2023-07-22T10:45:40.0740174Z =========== -2023-07-22T10:45:40.0741115Z c=>0xc00042a120 | c.Wsconn=>0x0 -2023-07-22T10:45:40.0741520Z =========== -2023-07-22T10:45:40.0741693Z pkg=rpc/subscription -2023-07-22T10:45:40.0742185Z 2023-07-22T10:45:40Z ERROR -2023-07-22T10:45:40.0742291Z -2023-07-22T10:45:40.0743984Z msg => {Jsonrpc:2.0 Method:state_storage Params:{Result:{Changes:[[0x6b6579 0x76616c7565]] Block:0x0000000000000000000000000000000000000000000000000000000000000000} SubscriptionID:0}} -2023-07-22T10:45:40.0744225Z -2023-07-22T10:45:40.0744415Z pkg=rpc/subscription ---- FAIL: TestStorageObserver_Update (0.00s) -2023-07-22T10:45:40.0744945Z panic: runtime error: invalid memory address or nil pointer dereference -2023-07-22T10:45:40.0745334Z panic: runtime error: invalid memory address or nil pointer dereference [recovered] -2023-07-22T10:45:40.0745647Z panic: runtime error: invalid memory address or nil pointer dereference -2023-07-22T10:45:40.0746014Z [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xf2edeb] -2023-07-22T10:45:40.0746151Z -2023-07-22T10:45:40.0788776Z goroutine 69 [running]: -2023-07-22T10:45:40.0789530Z testing.tRunner.func1.2({0x105ce20, 0x1ba2f20}) -2023-07-22T10:45:40.0792464Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1526 +0x24e -2023-07-22T10:45:40.0792731Z testing.tRunner.func1() -2023-07-22T10:45:40.0794753Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1529 +0x39f - - -2023-07-22T10:45:40.0796264Z panic({0x105ce20, 0x1ba2f20}) -2023-07-22T10:45:40.0797775Z /opt/hostedtoolcache/go/1.20.6/x64/src/runtime/panic.go:884 +0x213 -2023-07-22T10:45:40.0799266Z github.com/gorilla/websocket.(*Conn).Close(...) -2023-07-22T10:45:40.0800820Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:345 -2023-07-22T10:45:40.0802337Z github.com/ChainSafe/gossamer/dot/rpc/subscription.setupWSConn.func3() -2023-07-22T10:45:40.0804075Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/helpers_test.go:48 +0x4b - - -2023-07-22T10:45:40.0805589Z panic({0x105ce20, 0x1ba2f20}) -2023-07-22T10:45:40.0807069Z /opt/hostedtoolcache/go/1.20.6/x64/src/runtime/panic.go:884 +0x213 -2023-07-22T10:45:40.0808568Z github.com/gorilla/websocket.(*Conn).beginMessage(0x0, 0xc0000d25a0, 0x1) -2023-07-22T10:45:40.0810088Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:479 +0x27 -2023-07-22T10:45:40.0811567Z github.com/gorilla/websocket.(*Conn).NextWriter(0x0, 0x1) -2023-07-22T10:45:40.0813087Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:520 +0x45 -2023-07-22T10:45:40.0814632Z github.com/gorilla/websocket.(*Conn).WriteJSON(0xc00037e150?, {0x10e79e0, 0xc0000cea00}) -2023-07-22T10:45:40.0816162Z /home/runner/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/json.go:24 +0x45 -2023-07-22T10:45:40.0817675Z github.com/ChainSafe/gossamer/dot/rpc/subscription.(*WSConn).safeSend(0xc00042a120, {0x10e79e0, 0xc0000cea00}) -2023-07-22T10:45:40.0819325Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/websocket.go:414 +0x186 -2023-07-22T10:45:40.0820868Z github.com/ChainSafe/gossamer/dot/rpc/subscription.(*StorageObserver).Update(0xc000153e48, 0xc000153f20) -2023-07-22T10:45:40.0822480Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/listeners.go:83 +0x426 -2023-07-22T10:45:40.0824185Z github.com/ChainSafe/gossamer/dot/rpc/subscription.TestStorageObserver_Update(0x40f559?) -2023-07-22T10:45:40.0825924Z /home/runner/actions-runner/_work/gossamer/gossamer/dot/rpc/subscription/listeners_integration_test.go:67 +0x4f3 -2023-07-22T10:45:40.0827414Z testing.tRunner(0xc0000d4820, 0x12ffa40) -2023-07-22T10:45:40.0828572Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1576 +0x10b -2023-07-22T10:45:40.0828765Z created by testing.(*T).Run -2023-07-22T10:45:40.0829031Z /opt/hostedtoolcache/go/1.20.6/x64/src/testing/testing.go:1629 +0x3ea -2023-07-22T10:45:40.0829395Z FAIL github.com/ChainSafe/gossamer/dot/rpc/subscription 0.017s -2023-07-22T10:45:40.0831211Z FAIL \ No newline at end of file From 5b2eebfb9af8d9a0679e69bae57fd7ca5a7b1bca Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Sun, 23 Jul 2023 01:40:35 +0530 Subject: [PATCH 3/9] clean up --- dot/rpc/subscription/helpers_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dot/rpc/subscription/helpers_test.go b/dot/rpc/subscription/helpers_test.go index 9e24f14027..ce5bee0e87 100644 --- a/dot/rpc/subscription/helpers_test.go +++ b/dot/rpc/subscription/helpers_test.go @@ -42,8 +42,7 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { defer server.Close() wsURL := "ws" + strings.TrimPrefix(server.URL, "http") - ws, r, err := websocket.DefaultDialer.Dial(wsURL, nil) - defer r.Body.Close() + ws, _, err := websocket.DefaultDialer.Dial(wsURL, nil) require.NoError(t, err) // Wait for the WebSocket connection to be ready before proceeding From 53e39b7e716201b7a2502ee4f256198f81337fd5 Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Sun, 23 Jul 2023 01:47:01 +0530 Subject: [PATCH 4/9] lint --- dot/rpc/subscription/helpers_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dot/rpc/subscription/helpers_test.go b/dot/rpc/subscription/helpers_test.go index ce5bee0e87..119a856f04 100644 --- a/dot/rpc/subscription/helpers_test.go +++ b/dot/rpc/subscription/helpers_test.go @@ -42,7 +42,9 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { defer server.Close() wsURL := "ws" + strings.TrimPrefix(server.URL, "http") - ws, _, err := websocket.DefaultDialer.Dial(wsURL, nil) + ws, r, err := websocket.DefaultDialer.Dial(wsURL, nil) + r.Body.Close() + require.NoError(t, err) // Wait for the WebSocket connection to be ready before proceeding From e8df5fcce35aafd3dca7c83d873a17e41f998319 Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Sun, 23 Jul 2023 13:13:47 +0530 Subject: [PATCH 5/9] extend ctx deadline for all nodes to be connected --- tests/rpc/system_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rpc/system_integration_test.go b/tests/rpc/system_integration_test.go index e7230f3700..c3001b9d6f 100644 --- a/tests/rpc/system_integration_test.go +++ b/tests/rpc/system_integration_test.go @@ -63,7 +63,7 @@ func TestStableNetworkRPC(t *testing.T) { //nolint:tparallel // wait until all nodes are connected t.Log("waiting for all nodes to be connected") - peerTimeout, peerCancel := context.WithTimeout(context.Background(), 120*time.Second) + peerTimeout, peerCancel := context.WithTimeout(context.Background(), 150*time.Second) defer peerCancel() err := retry.UntilOK(peerTimeout, 10*time.Second, func() (bool, error) { for _, node := range nodes { From c2b5cee7e0f4bc8c6891e6bde7aa6912095c6d37 Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Sun, 23 Jul 2023 13:40:36 +0530 Subject: [PATCH 6/9] draft --- dot/rpc/subscription/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/rpc/subscription/helpers_test.go b/dot/rpc/subscription/helpers_test.go index 119a856f04..f7425c1142 100644 --- a/dot/rpc/subscription/helpers_test.go +++ b/dot/rpc/subscription/helpers_test.go @@ -43,7 +43,7 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { wsURL := "ws" + strings.TrimPrefix(server.URL, "http") ws, r, err := websocket.DefaultDialer.Dial(wsURL, nil) - r.Body.Close() + defer r.Body.Close() require.NoError(t, err) From 47a0e0c4b560a6d4529e39e7ffd64831964b005d Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Mon, 24 Jul 2023 17:06:56 +0530 Subject: [PATCH 7/9] draft --- tests/rpc/system_integration_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/rpc/system_integration_test.go b/tests/rpc/system_integration_test.go index c3001b9d6f..5a5e6ba9f5 100644 --- a/tests/rpc/system_integration_test.go +++ b/tests/rpc/system_integration_test.go @@ -56,11 +56,14 @@ func TestStableNetworkRPC(t *testing.T) { //nolint:tparallel select { case <-timer.C: case <-ctx.Done(): + t.Log("=====|TestStableNetworkRPC - select|=====") timer.Stop() return } } + t.Log("=====|TestStableNetworkRPC - after for loop|=====") + // wait until all nodes are connected t.Log("waiting for all nodes to be connected") peerTimeout, peerCancel := context.WithTimeout(context.Background(), 150*time.Second) From 3de784d27615fe8a879e56317de4911a7cfee5cc Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Mon, 24 Jul 2023 17:18:05 +0530 Subject: [PATCH 8/9] clean up --- tests/rpc/system_integration_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/rpc/system_integration_test.go b/tests/rpc/system_integration_test.go index 5a5e6ba9f5..e7230f3700 100644 --- a/tests/rpc/system_integration_test.go +++ b/tests/rpc/system_integration_test.go @@ -56,17 +56,14 @@ func TestStableNetworkRPC(t *testing.T) { //nolint:tparallel select { case <-timer.C: case <-ctx.Done(): - t.Log("=====|TestStableNetworkRPC - select|=====") timer.Stop() return } } - t.Log("=====|TestStableNetworkRPC - after for loop|=====") - // wait until all nodes are connected t.Log("waiting for all nodes to be connected") - peerTimeout, peerCancel := context.WithTimeout(context.Background(), 150*time.Second) + peerTimeout, peerCancel := context.WithTimeout(context.Background(), 120*time.Second) defer peerCancel() err := retry.UntilOK(peerTimeout, 10*time.Second, func() (bool, error) { for _, node := range nodes { From 694450e86432593f036a461f02bbb85e3e4218da Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Mon, 24 Jul 2023 17:21:23 +0530 Subject: [PATCH 9/9] handle deepsource error --- dot/rpc/subscription/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/rpc/subscription/helpers_test.go b/dot/rpc/subscription/helpers_test.go index f7425c1142..119a856f04 100644 --- a/dot/rpc/subscription/helpers_test.go +++ b/dot/rpc/subscription/helpers_test.go @@ -43,7 +43,7 @@ func setupWSConn(t *testing.T) (*WSConn, *websocket.Conn, func()) { wsURL := "ws" + strings.TrimPrefix(server.URL, "http") ws, r, err := websocket.DefaultDialer.Dial(wsURL, nil) - defer r.Body.Close() + r.Body.Close() require.NoError(t, err)