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

Refactor timer gate and fix goroutine leak problem #6630

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

Shaddoll
Copy link
Member

@Shaddoll Shaddoll commented Jan 16, 2025

What changed?

  • Move timer gate interface and implementation to common/clock package
  • Rename RemoteTimerGate interface to EventTimerGate
  • Change the implementation of localTimerGate:
    • get rid of the goroutine and fix the goroutine leak problem in history queue
    • make it multi goroutine safe
    • make it behave like golang's builtin time.Timer type
  • Remove Close method and Introduce Stop method which has a different behavior:
    • The Stop method behaves like the Stop method of time.Timer. It just clears the existing timer if any. A new timer can be reset via Update method.

Why?
Code refactoring and bug fixes

How did you test it?
unit tests

Potential risks

Release notes

Documentation Changes

if !t.timer.Stop() {
// drain the existing signal if exist
// TODO: the drain can be removed after go 1.23
<-t.timer.Chan()
Copy link
Member

Choose a reason for hiding this comment

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

should we change this to avoid blocking?

select {
	case <-t.timer.Chan():
	default:
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

It's safe to block. As of go 1.23, Stop method always returns true if the timer is not read from the channel, so we don't go to this branch. And before go 1.23, this is the correct way to stop a timer and drain the channel.

@Shaddoll Shaddoll merged commit fa6580d into cadence-workflow:master Jan 16, 2025
22 checks passed
@Shaddoll Shaddoll deleted the gate branch January 16, 2025 22:23
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.

2 participants