Skip to content

Commit

Permalink
adding logs where it may be possible to call Close() on resources tha… (
Browse files Browse the repository at this point in the history
#13595)

* adding logs where it may be possible to call Close() on resources that manage lifecycle of mercury WSRPC client and related components such as connection pool and cacheset

* changeset

* update log statement

* Update core/services/relay/evm/mercury/wsrpc/cache/cache_set.go

Co-authored-by: Sam <samsondav@protonmail.com>

* Update core/services/relay/evm/mercury/transmitter.go

Co-authored-by: Sam <samsondav@protonmail.com>

---------

Co-authored-by: Sam <samsondav@protonmail.com>
  • Loading branch information
akuzni2 and samsondav authored Jun 18, 2024
1 parent 74a4d16 commit 58f1286
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-hounds-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

debug log additions #internal
1 change: 1 addition & 0 deletions core/services/relay/evm/mercury/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ func (mt *mercuryTransmitter) Start(ctx context.Context) (err error) {

func (mt *mercuryTransmitter) Close() error {
return mt.StopOnce("MercuryTransmitter", func() error {
mt.lggr.Debug("Closing MercuryTransmitter")
// Drain all the queues first
var qs []io.Closer
for _, s := range mt.servers {
Expand Down
1 change: 1 addition & 0 deletions core/services/relay/evm/mercury/wsrpc/cache/cache_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (cs *cacheSet) Start(context.Context) error {

func (cs *cacheSet) Close() error {
return cs.StopOnce("CacheSet", func() error {
cs.lggr.Debug("Closing CacheSet")
cs.Lock()
defer cs.Unlock()
caches := maps.Values(cs.caches)
Expand Down
3 changes: 3 additions & 0 deletions core/services/relay/evm/mercury/wsrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ func (w *client) runloop() {
// resetTransport disconnects and reconnects to the mercury server
func (w *client) resetTransport() {
w.connectionResetCountMetric.Inc()
w.logger.Debug("ResetTransport starting")
ok := w.IfStarted(func() {
w.logger.Debugw("ResetTransport closing wsrpc connection", "state", w.conn.GetState())
w.conn.Close() // Close is safe to call multiple times
})
if !ok {
Expand All @@ -209,6 +211,7 @@ func (w *client) resetTransport() {

func (w *client) Close() error {
return w.StopOnce("WSRPC Client", func() error {
w.logger.Debugw("Closing WSRPC client", "state", w.conn.GetState())
close(w.chStop)
w.conn.Close()
w.wg.Wait()
Expand Down
3 changes: 3 additions & 0 deletions core/services/relay/evm/mercury/wsrpc/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (conn *connection) ensureStartedClient(ctx context.Context) error {
}

func (conn *connection) checkin(checkinCco *clientCheckout) {
conn.lggr.Debug("Checking in client", "serverURL", conn.serverURL, "checkouts", len(conn.checkouts))
conn.mu.Lock()
defer conn.mu.Unlock()
var removed bool
Expand All @@ -91,6 +92,7 @@ func (conn *connection) checkin(checkinCco *clientCheckout) {
}

func (conn *connection) forceCloseAll() (err error) {
conn.lggr.Debug("Force closing connection", "serverURL", conn.serverURL)
conn.mu.Lock()
defer conn.mu.Unlock()
if conn.Client != nil {
Expand Down Expand Up @@ -199,6 +201,7 @@ func (p *pool) Start(ctx context.Context) error {
}

func (p *pool) Close() (merr error) {
p.lggr.Debugw("Closing connection resources in WSRPC connection pool", "numConnections", len(p.connections))
p.mu.Lock()
defer p.mu.Unlock()
p.closed = true
Expand Down

0 comments on commit 58f1286

Please sign in to comment.