Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

fix /event response stop immediately #2602

Merged
merged 1 commit into from Jan 20, 2017

Conversation

realityone
Copy link
Contributor

Swarm /events API may be will stop immediately at sometime.

After digging these codes I found that we should be carefully to stop a timer. A timer maybe has already expired, even the duration is zero.

We can write an example to prove it:

package main

import (
	"fmt"
	"time"
)

func main() {

	for i := 0; i < 100; i++ {
		go func(c int) {
			timer := time.NewTimer(0)
			if !timer.Stop() {
				fmt.Printf("Timer stop failed at, %d\n", c)
			}
		}(i)
	}
}

Save as timerTest.go and go run with it:

[realityone@rEimu ~/Desktop]$ go run timerTest.go 
Timer stop failed at, 27
[realityone@rEimu ~/Desktop]$ go run timerTest.go 
Timer stop failed at, 41
[realityone@rEimu ~/Desktop]$ go run timerTest.go 
Timer stop failed at, 32
Timer stop failed at, 1
Timer stop failed at, 62
[realityone@rEimu ~/Desktop]$ go run timerTest.go 
Timer stop failed at, 13
Timer stop failed at, 57
Timer stop failed at, 83
[realityone@rEimu ~/Desktop]$ 

So we have to check the timer.Stop return value and drain the channel manually.

Signed-off-by: realityone realityone@me.com

Signed-off-by: realityone <realityone@me.com>
@dongluochen
Copy link
Contributor

LGTM

@dongluochen dongluochen added this to the 1.2.7 milestone Jan 20, 2017
@dongluochen
Copy link
Contributor

Ping @nishanttotla @allencloud

Copy link
Contributor

@nishanttotla nishanttotla left a comment

Choose a reason for hiding this comment

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

LGTM

@nishanttotla nishanttotla merged commit c0b4734 into docker-archive:master Jan 20, 2017
@nishanttotla
Copy link
Contributor

Thanks @realityone!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants