-
Notifications
You must be signed in to change notification settings - Fork 613
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
Conversation
pkg/machinery/client/client.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIll do.
Always close the connection, even if we forgot to do this ourselves. Signed-off-by: Dmitriy Matrenichev <[email protected]>
/m |
Always close the connection, even if we forgot to do this ourselves.