Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure proper closure of client.Client.conn with finalizer #10255

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

DmitriyMV
Copy link
Member

Always close the connection, even if we forgot to do this ourselves.

@@ -173,11 +174,15 @@ func New(_ context.Context, opts ...OptionFunc) (c *Client, err error) {
c.Inspect = &InspectClient{c.InspectClient}
c.COSI = state.WrapCore(client.NewAdapter(cosiv1alpha1.NewStateClient(c.conn)))

// Just like Go team does in their os.File internals, lets ensure that we always close the connection.
runtime.SetFinalizer(c.conn, (*grpcConnectionWrapper).Close)
Copy link
Member

Choose a reason for hiding this comment

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

in Omni we already SetFinalizer on the *Client itself, I'm not sure how this would play out if used together.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's why we set finalizer on conn (private field) and not the Client.

Copy link
Member

Choose a reason for hiding this comment

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

can we have a test for it as well? idk how hard it would be, but it'd be nice to verify that it actually gets GC'd

Copy link
Member Author

Choose a reason for hiding this comment

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

WIll do.

Verified

This commit was signed with the committer’s verified signature.
DmitriyMV Dmitriy Matrenichev
Always close the connection, even if we forgot to do this ourselves.

Signed-off-by: Dmitriy Matrenichev <[email protected]>
@DmitriyMV
Copy link
Member Author

/m

@talos-bot talos-bot merged commit 673ca4b into siderolabs:main Jan 31, 2025
51 checks passed
@DmitriyMV DmitriyMV deleted the close-conn branch January 31, 2025 04:30
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.

None yet

4 participants