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

Correctly handle select on multiple channels in Queues (#22146) #22428

Merged
merged 3 commits into from
Jan 13, 2023

Commits on Jan 13, 2023

  1. Correctly handle select on multiple channels in Queues (go-gitea#22146)

    Backport go-gitea#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
     go-gitea#22145
    
    Fix go-gitea#22145
    
    Signed-off-by: Andrew Thornton <art27@cantab.net>
    
    Signed-off-by: Andrew Thornton <art27@cantab.net>
    zeripath committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    857b1a1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    416d803 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    613555c View commit details
    Browse the repository at this point in the history