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 race condition on OffsetManager shutdown #657

Closed
wants to merge 1 commit into from

Conversation

eapache
Copy link
Contributor

@eapache eapache commented May 6, 2016

If updateCommitted ran between the Unlock call and the read from clean
then we might miss the transition message and hang. Instead, read
unconditionally from clean and launch a second goroutine that writes a
message to it if we were already clean.

The additional local cancel is necessary to avoid leaking the second (writing)
goroutine in the event that the main shutdown goroutine picks up a real
transitional event before our extra writer even runs; without it the writer
could block writing forever.

@wvanbergen @hasnickl fixes #656

If `updateCommitted` ran between the `Unlock` call and the read from `clean`
then we might miss the transition message and hang. Instead, read
unconditionally from `clean` and launch a second goroutine that *writes* a
message to it if we were already clean.

The additional local `cancel` is necessary to avoid leaking the second (writing)
goroutine in the event that the main shutdown goroutine picks up a real
transitional event before our extra writer even runs; without it the writer
could block writing forever.
@hasnickl
Copy link

hasnickl commented May 6, 2016

If the first go func runs while pom is dirty, updateCommitted could run and finish before the second go func receives on clean

A possible solution is to have an internal flag like pom.shutdown. AsyncClose can lock pom, set shutdown to true, start the go routine to read from clean and unlock.

updateCommitted could then change the select with default to conditionally start a go routine:

if pom.shutdown {
  go func(){
    pom.clean <- none{}
  }
}

perhaps MarkOffset would also check this flag to prevent state going to dirty again while shutting down.

Any thoughts on this?

@eapache
Copy link
Contributor Author

eapache commented May 6, 2016

If the first go func runs while pom is dirty, updateCommitted could run and finish before the second go func receives on clean

You're right, I must have been asleep when I cooked up this solution.

@eapache eapache closed this May 6, 2016
@eapache eapache deleted the offset-manager-shutdown-bug branch May 6, 2016 20:13
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.

OffsetManager.Close() race condition
2 participants