Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

allow holder to close/open/close without panic on closing closed channel #1686

Merged
merged 1 commit into from Oct 11, 2018

Conversation

travisturner
Copy link
Member

Overview

This PR uses a sync.Once to prevent closing the Holder.opened channel after it has been closed. The downside to this solution is that there's no support for waiting on Holder.opened on the second Open() event, but since this is a non-exported channel, that's currently not functionality we need internally.

It also re-initializes the Holder.closing channel inside the Open() method. This allows multiple calls to Close() without panic. Here again, since Holder.closing is not exported, it doesn't cause a problem to initialize it after creation of Holder.

Fixes #1685

Pull request checklist

Code review checklist

This is the checklist that the reviewer will follow while reviewing your pull request. You do not need to do anything with this checklist, but be aware of what the reviewer will be looking for.

  • Ensure that any changes to external docs have been included in this pull request.
  • If the changes require that minor/major versions need to be updated, tag the PR appropriately.
  • Ensure the new code is properly commented and follows Idiomatic Go.
  • Check that tests have been written and that they cover the new functionality.
  • Run tests and ensure they pass.
  • Build and run the code, performing any applicable integration testing.

Copy link
Member

@jaffee jaffee left a comment

Choose a reason for hiding this comment

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

what if Close reset the opened chan? I think that would avoid races and the need for the once

@travisturner
Copy link
Member Author

I thought about that, but I'm not sure what would happen if Close() was called asynchronously, at the same time, or immediately after, calling Open(). That could result in a process that is blocking on opened never releasing the block. I believe in that case, Open() would end up closing the channel that was reset in the Close() method. Maybe it doesn't matter since these are all non-exported channels, but I felt like that was more confusing. And we could always implement it that way later if there was a case where we needed to block on opened more than once.

@jaffee
Copy link
Member

jaffee commented Oct 10, 2018

I think not calling Open and Close concurrently and calling Open before Close is a reasonable API restriction.

My concern with the current implementation is that we might expose the ability to check if a holder is opened (e.g. via a WaitForOpen method or similar, but forget that that will only work the first time.

@travisturner
Copy link
Member Author

That's ok with me. I don't think the asynchronous Open/Close is really a concern at this point. I updated it to reset both of those channels.

@travisturner travisturner merged commit f62dbc0 into FeatureBaseDB:master Oct 11, 2018
@travisturner travisturner deleted the holder-reopen branch October 11, 2018 12:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let pilosa.Holder be reopened
2 participants