diff options
| author | Ian Lance Taylor <iant@golang.org> | 2019-11-05 07:24:18 -0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2019-11-05 18:37:06 +0000 |
| commit | c3cef0bfe5f503ee016fc61e58f5ee1b78dbd962 (patch) | |
| tree | 828d3cadc8c5ac7972044aad290a393b454009e3 /src/net | |
| parent | a9c0cc6f6744654de7f8fdff52f5da601a109d11 (diff) | |
| download | go-c3cef0bfe5f503ee016fc61e58f5ee1b78dbd962.tar.xz | |
runtime: keep adjusted timers in timerMoving status until moved
Before this CL adjustTimers left timers being moved in an inconsistent
state: status timerWaiting but not on a P. Simplify the code by
leaving the timers in timerMoving status until they are actually moved.
Other functions (deltimer, modtimer) will wait until the move is complete
before changing anything on the timer. This does leave timers in timerMoving
state for longer, but still not all that long.
Fixes #35367
Change-Id: I31851002fb4053bd6914139125b4c82a68bf6fb2
Reviewed-on: https://go-review.googlesource.com/c/go/+/205418
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/net')
| -rw-r--r-- | src/net/timeout_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/net/timeout_test.go b/src/net/timeout_test.go index e90c16f34b..f54c9564f9 100644 --- a/src/net/timeout_test.go +++ b/src/net/timeout_test.go @@ -1033,3 +1033,43 @@ func TestReadWriteDeadlineRace(t *testing.T) { }() wg.Wait() // wait for tester goroutine to stop } + +// Issue 35367. +func TestConcurrentSetDeadline(t *testing.T) { + ln, err := newLocalListener("tcp") + if err != nil { + t.Fatal(err) + } + defer ln.Close() + + const goroutines = 8 + const conns = 10 + const tries = 100 + + var c [conns]Conn + for i := 0; i < conns; i++ { + c[i], err = Dial(ln.Addr().Network(), ln.Addr().String()) + if err != nil { + t.Fatal(err) + } + defer c[i].Close() + } + + var wg sync.WaitGroup + wg.Add(goroutines) + now := time.Now() + for i := 0; i < goroutines; i++ { + go func(i int) { + defer wg.Done() + // Make the deadlines steadily earlier, + // to trigger runtime adjusttimers calls. + for j := tries; j > 0; j-- { + for k := 0; k < conns; k++ { + c[k].SetReadDeadline(now.Add(2*time.Hour + time.Duration(i*j*k)*time.Second)) + c[k].SetWriteDeadline(now.Add(1*time.Hour + time.Duration(i*j*k)*time.Second)) + } + } + }(i) + } + wg.Wait() +} |
