GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [Bug][fn] Go functions do not reset idleTimer correctly. · Issue #20449 · apache/pulsar Closed flowchartsman/pulsar #5Closed Copy link Labels type/bugThe PR fixed a bug or issue reported a bug DescriptionSearch before asking
VersionThe code in idleDuration := getIdleTimeout(time.Millisecond * time.Duration(gi.context.instanceConf.killAfterIdleMs)) idleTimer := time.NewTimer(idleDuration) defer idleTimer.Stop() CLOSE: for { idleTimer.Reset(idleDuration) select { case cm := <-channel: // handle message case <-idleTimer.C: close(channel) // this is not great either, but that's a separate bug ;) break CLOSE } } However, this does not account for the idle timer firing during work. If it does, then the reset will not have the desired effect, and the idle clause will fire erroneously on a subsequent loop, since there's now a timestamp on the channel. Minimal reproduce stepHere's a simple repro: package main import "fmt" import "time" func main() { const idleDuration = 250*time.Millisecond work := make(chan int,2) work <- 1 work <- 2 t := time.NewTimer(idleDuration) EVENTLOOP: for { t.Reset(idleDuration) fmt.Println("waiting for new work") select { case w := <- work: fmt.Printf("doing work on %d\n", w) time.Sleep(500*time.Millisecond) fmt.Println("done with work") case <- t.C: fmt.Println("timed out") break EVENTLOOP } } } Run that a few times, and you'll see: This is exactly what would happen in a Go function, only it would then call What did you expect to see?n/a What did you see instead?n/a Anything else?The correct fix is to call CLOSE: for { select { case cm := <-channel: // handle message case <-idleTimer.C: close(channel) break CLOSE } if !idleTimer.Stop() { <-idleTimer.C } } Are you willing to submit a PR?
Activity
MetadataMetadataAssigneesLabelstype/bugThe PR fixed a bug or issue reported a bug TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |