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 leaky goroutines in matching #5499

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions service/matching/taskListManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Copy link
Member

Choose a reason for hiding this comment

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

this is most probably because of Go 1.21 != CI (1.20)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets address this after @Groxx PR. Then everything will be unified.

"github.com/uber/cadence/common/cache"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/dynamicconfig"
Expand Down
10 changes: 10 additions & 0 deletions service/matching/taskReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"errors"
"runtime"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -80,6 +81,9 @@ type (
dispatchTask func(context.Context, *InternalTask) error
getIsolationGroupForTask func(context.Context, *persistence.TaskInfo) (string, error)
ratePerSecond func() float64

// stopWg is used to wait for all dispatchers to stop.
stopWg sync.WaitGroup
}
)

Expand Down Expand Up @@ -137,6 +141,7 @@ func (tr *taskReader) Stop() {
tag.Error(err))
}
tr.taskGC.RunNow(tr.taskAckManager.GetAckLevel())
tr.stopWg.Wait()
}
}

Expand All @@ -149,6 +154,8 @@ func (tr *taskReader) Signal() {
}

func (tr *taskReader) dispatchBufferedTasks(isolationGroup string) {
tr.stopWg.Add(1)
defer tr.stopWg.Done()
Comment on lines +157 to +158
Copy link
Member

Choose a reason for hiding this comment

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

Looks like a generic approach for stopping. I wonder if it's possible to have some OOP around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OOP in Go is hard, I'm not aware of generic solutions on this.

dispatchLoop:
for {
select {
Expand All @@ -168,6 +175,9 @@ dispatchLoop:
}

func (tr *taskReader) getTasksPump() {
tr.stopWg.Add(1)
defer tr.stopWg.Done()

updateAckTimer := time.NewTimer(tr.config.UpdateAckInterval())
defer updateAckTimer.Stop()
getTasksPumpLoop:
Expand Down