Skip to content

Commit

Permalink
1.4: panic on failover (#6556)
Browse files Browse the repository at this point in the history
* core/chains/evm/client: check for non-nil error instead of nil interface value

* core/chains/evm/client: expand test to cover failed EthSubscribe

Co-authored-by: Andrei Smirnov <[email protected]>
(cherry picked from commit de23ce9)
  • Loading branch information
jmank88 authored and HenryNguyen5 committed May 5, 2022
1 parent a5f089f commit a3d74b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 6 additions & 7 deletions core/chains/evm/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ func (n *node) EthSubscribe(ctx context.Context, channel chan<- *evmtypes.Head,
lggr.Debug("RPC call: evmclient.Client#EthSubscribe")
start := time.Now()
sub, err := n.ws.rpc.EthSubscribe(ctx, channel, args...)
if err == nil {
n.registerSub(sub)
}
duration := time.Since(start)

n.logResult(lggr, err, duration, n.getRPCDomain(), "EthSubscribe",
Expand All @@ -477,9 +480,6 @@ func (n *node) EthSubscribe(ctx context.Context, channel chan<- *evmtypes.Head,
"err", err,
)

if sub != nil {
n.registerSub(sub)
}
return sub, err
}

Expand Down Expand Up @@ -904,6 +904,9 @@ func (n *node) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery,
lggr.Debug("RPC call: evmclient.Client#SubscribeFilterLogs")
start := time.Now()
sub, err = n.ws.geth.SubscribeFilterLogs(ctx, q, ch)
if err == nil {
n.registerSub(sub)
}
err = n.wrapWS(err)
duration := time.Since(start)

Expand All @@ -913,10 +916,6 @@ func (n *node) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery,
"err", err,
)

if sub != nil {
n.registerSub(sub)
}

return
}

Expand Down
6 changes: 6 additions & 0 deletions core/chains/evm/client/node_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.uber.org/atomic"
"go.uber.org/zap"

evmtypes "github.com/smartcontractkit/chainlink/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/core/internal/testutils"
"github.com/smartcontractkit/chainlink/core/logger"
)
Expand Down Expand Up @@ -157,10 +158,15 @@ func TestUnit_NodeLifecycle_aliveLoop(t *testing.T) {
dial(t, n)
defer n.Close()

_, err := n.EthSubscribe(testutils.Context(t), make(chan *evmtypes.Head))
assert.Error(t, err)

n.wg.Add(1)
n.aliveLoop()

assert.Equal(t, NodeStateUnreachable, n.State())
// sc-39341: ensure failed EthSubscribe didn't register a (*rpc.ClientSubscription)(nil) which would lead to a panic on Unsubscribe
assert.Len(t, n.subs, 0)
})

t.Run("if remote RPC connection is closed transitions to unreachable", func(t *testing.T) {
Expand Down

0 comments on commit a3d74b4

Please sign in to comment.