Skip to content

Commit

Permalink
fix invalid pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed Nov 10, 2023
1 parent a8f13a3 commit 754f423
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/flow/internal/worker/worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,32 +148,32 @@ func (w *workQueue) taskDone(key string) {
func (w *workQueue) emitNextTask() {
var (
task func()
key *string
key string
index int
found = false
)

// Find the first key in waitingOrder that is not yet running
for i, k := range w.waitingOrder {
if _, alreadyRunning := w.running[k]; !alreadyRunning {
key = &k
index = i
found, key, index = true, k, i
}
}

// Return if we didn't find any task ready to run
if key == nil {
if !found {
return
}

// Remove the task from waiting and add it to running set
w.waitingOrder = append(w.waitingOrder[:index], w.waitingOrder[index+1:]...)
task = w.waiting[*key]
delete(w.waiting, *key)
w.running[*key] = struct{}{}
task = w.waiting[key]
delete(w.waiting, key)
w.running[key] = struct{}{}

// Wrap the actual task to make sure we mark it as done when it finishes
wrapped := func() {
defer w.taskDone(*key)
defer w.taskDone(key)
task()
}

Expand Down

0 comments on commit 754f423

Please sign in to comment.