From 58f12862452bbcb366ed9bedab2645da2185c365 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 18 Jun 2024 09:56:01 -0500 Subject: [PATCH] =?UTF-8?q?adding=20logs=20where=20it=20may=20be=20possibl?= =?UTF-8?q?e=20to=20call=20Close()=20on=20resources=20tha=E2=80=A6=20(#135?= =?UTF-8?q?95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Update core/services/relay/evm/mercury/transmitter.go Co-authored-by: Sam --------- Co-authored-by: Sam --- .changeset/angry-hounds-roll.md | 5 +++++ core/services/relay/evm/mercury/transmitter.go | 1 + core/services/relay/evm/mercury/wsrpc/cache/cache_set.go | 1 + core/services/relay/evm/mercury/wsrpc/client.go | 3 +++ core/services/relay/evm/mercury/wsrpc/pool.go | 3 +++ 5 files changed, 13 insertions(+) create mode 100644 .changeset/angry-hounds-roll.md diff --git a/.changeset/angry-hounds-roll.md b/.changeset/angry-hounds-roll.md new file mode 100644 index 00000000000..1525ecfb39c --- /dev/null +++ b/.changeset/angry-hounds-roll.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +debug log additions #internal diff --git a/core/services/relay/evm/mercury/transmitter.go b/core/services/relay/evm/mercury/transmitter.go index 7abd926255a..4e5414ac4bd 100644 --- a/core/services/relay/evm/mercury/transmitter.go +++ b/core/services/relay/evm/mercury/transmitter.go @@ -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 { diff --git a/core/services/relay/evm/mercury/wsrpc/cache/cache_set.go b/core/services/relay/evm/mercury/wsrpc/cache/cache_set.go index 7101cec39f3..0255258ae99 100644 --- a/core/services/relay/evm/mercury/wsrpc/cache/cache_set.go +++ b/core/services/relay/evm/mercury/wsrpc/cache/cache_set.go @@ -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) diff --git a/core/services/relay/evm/mercury/wsrpc/client.go b/core/services/relay/evm/mercury/wsrpc/client.go index b5d784face0..bb1b886ed97 100644 --- a/core/services/relay/evm/mercury/wsrpc/client.go +++ b/core/services/relay/evm/mercury/wsrpc/client.go @@ -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 { @@ -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() diff --git a/core/services/relay/evm/mercury/wsrpc/pool.go b/core/services/relay/evm/mercury/wsrpc/pool.go index 94c48736f5d..1ebd8cd5694 100644 --- a/core/services/relay/evm/mercury/wsrpc/pool.go +++ b/core/services/relay/evm/mercury/wsrpc/pool.go @@ -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 @@ -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 { @@ -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