Skip to content

Clean up dropped resources in relayer construction#1927

Open
ogtownsend wants to merge 3 commits intomainfrom
ogt/clean-up-potential-resource-drops-in-relayer-client
Open

Clean up dropped resources in relayer construction#1927
ogtownsend wants to merge 3 commits intomainfrom
ogt/clean-up-potential-resource-drops-in-relayer-client

Conversation

@ogtownsend
Copy link
Contributor

Requires

Supports

@github-actions
Copy link

github-actions bot commented Mar 25, 2026

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-common

View full report

jmank88
jmank88 previously approved these changes Mar 25, 2026
@ogtownsend ogtownsend marked this pull request as ready for review March 25, 2026 21:43
@ogtownsend ogtownsend requested review from a team as code owners March 25, 2026 21:43
Copilot AI review requested due to automatic review settings March 25, 2026 21:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent leaked/dropped resources during relayer construction in the LOOP relayer gRPC client/server wiring, supporting LINK-777.

Changes:

  • Return accumulated net.Resources (deps) from relayer/CCIP provider client-connection constructors so clientConn.refresh can close them on failure.
  • Fix a server-side resource closer bug where the CSA keystore resource was closing the wrong connection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 91 to +94
if err != nil {
return 0, nil, fmt.Errorf("Failed to create relayer client: failed request: %w", err)
return 0, deps, fmt.Errorf("Failed to create relayer client: failed request: %w", err)
}
return reply.RelayerID, nil, nil
return reply.RelayerID, deps, nil
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning deps here ensures resources are cleaned up when the request fails, but earlier error branches in this same NewClientConn callback still return nil deps after resources have already been started (e.g., failure serving the CSA keystore or capability registry). Because clientConn.refresh only closes the deps returned by this callback on error, those earlier paths can still leak the already-served resources. Return the accumulated deps (or explicitly close already-created resources) in those error branches as well, and consider passing prior resources as deps into subsequent ServeNew calls so they’re closed if a later ServeNew fails.

Copilot uses AI. Check for mistakes.
})
if err != nil {
return 0, nil, fmt.Errorf("Failed to create relayer client: failed to serve keystore: %w", err)
return 0, deps, fmt.Errorf("Failed to create relayer client: failed to serve keystore: %w", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmank88 do you have a preference for returning these deps or explicitly closing them here in the error block?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were closing everywhere before but it became very spammy. IIRC the original pattern was to just let them return naturally like:

Suggested change
return 0, deps, fmt.Errorf("Failed to create relayer client: failed to serve keystore: %w", err)
err = fmt.Errorf("Failed to create relayer client: failed to serve keystore: %w", err)
return

🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, I guess I'll leave it as-is then 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants