Skip to content

Commit

Permalink
Fix infinite stack overflow if caching is disabled (#11669)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav authored Jan 2, 2024
1 parent 1fa50ce commit 6b740c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/services/relay/evm/mercury/wsrpc/cache/cache_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (cs *cacheSet) Close() error {
func (cs *cacheSet) Get(ctx context.Context, client Client) (f Fetcher, err error) {
if cs.cfg.LatestReportTTL == 0 {
// caching disabled
return client, nil
return nil, nil
}
ok := cs.IfStarted(func() {
f, err = cs.get(ctx, client)
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/mercury/wsrpc/cache/cache_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func Test_CacheSet(t *testing.T) {

var err error
var f Fetcher
t.Run("with caching disabled, returns the passed client", func(t *testing.T) {
t.Run("with caching disabled, returns nil, nil", func(t *testing.T) {
assert.Len(t, disabledCs.caches, 0)

f, err = disabledCs.Get(ctx, c)
require.NoError(t, err)

assert.Same(t, c, f)
assert.Nil(t, f)
assert.Len(t, disabledCs.caches, 0)
})

Expand Down
17 changes: 10 additions & 7 deletions core/services/relay/evm/mercury/wsrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/wsrpc/pb"
)

// simulate start without dialling
func simulateStart(ctx context.Context, t *testing.T, c *client) {
require.NoError(t, c.StartOnce("Mock WSRPC Client", func() (err error) {
c.cache, err = c.cacheSet.Get(ctx, c)
return err
}))
}

var _ cache.CacheSet = &mockCacheSet{}

type mockCacheSet struct{}
Expand Down Expand Up @@ -160,9 +168,8 @@ func Test_Client_LatestReport(t *testing.T) {
c.conn = conn
c.rawClient = wsrpcClient

// simulate start without dialling
require.NoError(t, c.StartOnce("Mock WSRPC Client", func() error { return nil }))
servicetest.Run(t, cacheSet)
simulateStart(ctx, t, c)

for i := 0; i < 5; i++ {
r, err := c.LatestReport(ctx, req)
Expand Down Expand Up @@ -195,12 +202,8 @@ func Test_Client_LatestReport(t *testing.T) {
c.conn = conn
c.rawClient = wsrpcClient

// simulate start without dialling
require.NoError(t, c.StartOnce("Mock WSRPC Client", func() error { return nil }))
var err error
servicetest.Run(t, cacheSet)
c.cache, err = cacheSet.Get(ctx, c)
require.NoError(t, err)
simulateStart(ctx, t, c)

for i := 0; i < 5; i++ {
r, err := c.LatestReport(ctx, req)
Expand Down

0 comments on commit 6b740c5

Please sign in to comment.