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

Handle Client.Close on cloned clients #893

Merged
merged 6 commits into from
Sep 1, 2022

Conversation

cretz
Copy link
Member

@cretz cretz commented Aug 29, 2022

What was changed

Use a counter to make sure only the last Close() of a shared-connection set of clients applies.

Checklist

  1. Closes independent lifecycles for cloned clients #886

workflowClient := client.(*WorkflowClient)

// Confirm there is 1 unclosed client
require.EqualValues(t, 1, *workflowClient.unclosedClients)
Copy link
Member

Choose a reason for hiding this comment

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

technically should use atomic.LoadInt32, if you modify it with atomics, I think

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in a test case. I can trust my lack of race issues in my own test case.

Copy link
Member

Choose a reason for hiding this comment

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

I would do it just for consistency's sake. It's supposed to be an atomic int, it should be manipulated atomically even if Go lets you not do that. Trivial amount of extra typing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also access the pointers directly in a non-atomic way to compare they point to the same spot. But I will make the change.

// set it to a new pointer of max to prevent decrementing on repeated Close
// calls to this client. If the count has not reached zero, this close call is
// ignored.
if wc.unclosedClients != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this shouldn't ever be nil, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

I cannot trust all places that create a client will set this. That includes tests and other code paths.

if err := wc.conn.Close(); err != nil {
wc.logger.Warn("unable to close connection", tagError, err)

if wc.conn != nil {
Copy link
Member

Choose a reason for hiding this comment

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

when is this nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

Test cases w/ mocks. This logic has not changed, I just moved the condition from the top of the function to down here.

Copy link
Member

@dnr dnr left a comment

Choose a reason for hiding this comment

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

sounds good to me

@cretz
Copy link
Member Author

cretz commented Aug 29, 2022

This is reliably causing integration tests to go from 2 mins to 3. I am investigating...

EDIT: This was due to an unclosed client causing a temporary goroutine leak causing a timeout

@cretz cretz merged commit d1f860c into temporalio:master Sep 1, 2022
@cretz cretz deleted the cloned-client-close branch September 1, 2022 17:54
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.

independent lifecycles for cloned clients
3 participants