Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove panic recovery for wsrpc #15865

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions core/services/relay/evm/mercury/wsrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,6 @@ func (w *client) waitForReady(ctx context.Context) (err error) {

func (w *client) Transmit(ctx context.Context, req *pb.TransmitRequest) (resp *pb.TransmitResponse, err error) {
ok := w.IfStarted(func() {
defer func() {
if r := recover(); r != nil {
w.handlePanic(r)
resp = nil
err = fmt.Errorf("Transmit: caught panic: %v", r)
}
}()
w.logger.Trace("Transmit")
start := time.Now()
if err = w.waitForReady(ctx); err != nil {
Expand Down Expand Up @@ -360,13 +353,6 @@ func (w *client) handleTimeout(err error) {

func (w *client) LatestReport(ctx context.Context, req *pb.LatestReportRequest) (resp *pb.LatestReportResponse, err error) {
ok := w.IfStarted(func() {
defer func() {
if r := recover(); r != nil {
w.handlePanic(r)
resp = nil
err = fmt.Errorf("LatestReport: caught panic: %v", r)
}
}()
lggr := w.logger.With("req.FeedId", hexutil.Encode(req.FeedId))
lggr.Trace("LatestReport")
if err = w.waitForReady(ctx); err != nil {
Expand Down
66 changes: 0 additions & 66 deletions core/services/relay/evm/mercury/wsrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ package wsrpc

import (
"context"
"math/big"
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
grpc_connectivity "google.golang.org/grpc/connectivity"

"github.com/smartcontractkit/wsrpc"

"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
Expand Down Expand Up @@ -128,67 +123,6 @@ func Test_Client_Transmit(t *testing.T) {
}
})
})

t.Run("recovers panics in underlying client and attempts redial", func(t *testing.T) {
makeConn := func() *mocks.MockConn {
return &mocks.MockConn{
Ready: true,
State: grpc_connectivity.Ready,
InvokeF: func(ctx context.Context, method string, args interface{}, reply interface{}) error {
panic("TESTING CONN INVOKE PANIC")
},
}
}

ch := make(chan *mocks.MockConn, 100)
cnt := 0

f := func(ctxCaller context.Context, target string, opts ...wsrpc.DialOption) (Conn, error) {
cnt++
switch cnt {
case 1, 2:
conn := makeConn()
ch <- conn
return conn, nil
default:
t.Fatalf("too many dials, got: %d", cnt)
return nil, nil
}
}

clientKey := csakey.MustNewV2XXXTestingOnly(big.NewInt(rand.Int63()))
serverKey := csakey.MustNewV2XXXTestingOnly(big.NewInt(rand.Int63()))
opts := ClientOpts{
lggr,
clientKey,
serverKey.PublicKey,
"",
noopCacheSet,
f,
}
c := newClient(opts)

servicetest.Run(t, c)

// drain the channel
var conn *mocks.MockConn
select {
case conn = <-ch:
assert.Equal(t, 1, cnt)
default:
t.Fatalf("expected dial to be called")
}

_, err := c.Transmit(ctx, req)
require.EqualError(t, err, "Transmit: caught panic: TESTING CONN INVOKE PANIC")

// expect conn to be closed and re-dialed
conn2 := <-ch
assert.Equal(t, 2, cnt)

assert.True(t, conn.Closed)
assert.False(t, conn2.Closed)
})
}

func Test_Client_LatestReport(t *testing.T) {
Expand Down
Loading