You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/modules/queue
zeripath 3ad62127df
Correctly handle select on multiple channels in Queues (#22146) (#22428)
Backport #22146

There are a few places in FlushQueueWithContext which make an incorrect
assumption about how `select` on multiple channels works.

The problem is best expressed by looking at the following example:

```go
package main

import "fmt"

func main() {
    closedChan := make(chan struct{})
    close(closedChan)
    toClose := make(chan struct{})
    count := 0

    for {
        select {
        case <-closedChan:
            count++
            fmt.Println(count)
            if count == 2 {
                close(toClose)
            }
        case <-toClose:
            return
        }
    }
}
```

This PR double-checks that the contexts are closed outside of checking
if there is data in the dataChan. It also rationalises the WorkerPool
FlushWithContext because the previous implementation failed to handle
pausing correctly. This will probably fix the underlying problem in
 #22145

Fix #22145

Signed-off-by: Andrew Thornton <art27@cantab.net>
2 years ago
..
bytefifo.go Pause queues (#15928) 3 years ago
helper.go Add more linters to improve code readability (#19989) 3 years ago
manager.go Add number in queue status to monitor page (#18712) 3 years ago
queue.go Make WrappedQueues and PersistableChannelUniqueQueues Pausable (#18393) 3 years ago
queue_bytefifo.go Add more linters to improve code readability (#19989) 3 years ago
queue_channel.go Correctly handle select on multiple channels in Queues (#22146) (#22428) 2 years ago
queue_channel_test.go Prevent intermittent NPE in queue tests (#19301) 3 years ago
queue_disk.go Pause queues (#15928) 3 years ago
queue_disk_channel.go Add more linters to improve code readability (#19989) 3 years ago
queue_disk_channel_test.go test: use `T.TempDir` to create temporary test directory (#21043) 3 years ago
queue_disk_test.go test: use `T.TempDir` to create temporary test directory (#21043) 3 years ago
queue_redis.go Pause queues (#15928) 3 years ago
queue_test.go Add an abstract json layout to make it's easier to change json library (#16528) 4 years ago
queue_wrapped.go Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
setting.go Make WrappedQueues and PersistableChannelUniqueQueues Pausable (#18393) 3 years ago
unique_queue.go
unique_queue_channel.go Correctly handle select on multiple channels in Queues (#22146) (#22428) 2 years ago
unique_queue_channel_test.go Add Goroutine stack inspector to admin/monitor (#19207) 3 years ago
unique_queue_disk.go Pause queues (#15928) 3 years ago
unique_queue_disk_channel.go Add more linters to improve code readability (#19989) 3 years ago
unique_queue_redis.go Pause queues (#15928) 3 years ago
unique_queue_wrapped.go Make WrappedQueues and PersistableChannelUniqueQueues Pausable (#18393) 3 years ago
workerpool.go Correctly handle select on multiple channels in Queues (#22146) (#22428) 2 years ago