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

store: close bkt properly #5020

Merged
merged 2 commits into from
Jan 4, 2022
Merged

store: close bkt properly #5020

merged 2 commits into from
Jan 4, 2022

Conversation

GiedriusS
Copy link
Member

Just a small fix: add bkt closing to the run group instead of closing it
at the of the function that only sets things up. In practice, this
didn't cause a bug because Close() is a noop. But as good Go
programmers, let's Close() the bucket properly at the end of Thanos
Store's lifetime.

Just a small fix: add bkt closing to the run group instead of closing it
at the of the function that only sets things up. In practice, this
didn't cause a bug because Close() is a noop. But as good Go
programmers, let's Close() the bucket properly at the end of Thanos
Store's lifetime.

Signed-off-by: Giedrius Statkevičius <[email protected]>
Copy link
Collaborator

@matej-g matej-g left a comment

Choose a reason for hiding this comment

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

Always great to see best practices being turned into action 🙌 I was wondering about one thing, see comment.

runutil.CloseWithLogOnErr(logger, bkt, "bucket client")
}
}()
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm trying to follow the code - it looks like we're also closing bkt in another run group below at 365. Do we need both?

Also, are other components using bucket clients adhering to this or are they using simply defer instead as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct, I have missed that one. We were talking about this particular code snippet that I've edited in our meetings with Prem & Akansha so I haven't even bothered to check other places. With this, we can simply remove this code block. I don't know about all clients but I think it's customary to call Close() at the end of using some resource.

done := make(chan struct{})
g.Add(func() error {
<-done
return bkt.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we retain CloseWithLogOnErr here so that we can log the potential close error?

This is already covered by:
```
defer runutil.CloseWithLogOnErr(logger, bkt, "bucket client")
```

In the same file.

Signed-off-by: Giedrius Statkevičius <[email protected]>
@pull-request-size pull-request-size bot added size/XS and removed size/S labels Jan 4, 2022
Copy link
Member

@squat squat left a comment

Choose a reason for hiding this comment

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

nice 🌮 so, tl;dr we are already closing the bkt properly further on down

@squat squat merged commit 47b80b1 into thanos-io:main Jan 4, 2022
@GiedriusS GiedriusS deleted the close_properly branch January 4, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants