]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix trace.Stop deadlock when built with faketime
authorHiro <laciferin@gmail.com>
Wed, 21 Jun 2023 23:33:51 +0000 (23:33 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 27 Jun 2023 18:21:24 +0000 (18:21 +0000)
For #60806

Change-Id: I1ac18a6c7c703a1d6c4cd80f220059ba0be51e09
GitHub-Last-Rev: d300ca3f316d34f5013be43d01a9a473fe3000b2
GitHub-Pull-Request: golang/go#60834
Reviewed-on: https://go-review.googlesource.com/c/go/+/503356
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/trace.go

index ac80ca2902c4b6096ff854a9009d37f30402c4d8..a4d50d77a0102d880dd9b0d0efc5df6917b05bbc 100644 (file)
@@ -453,12 +453,17 @@ func StopTrace() {
                }
        }
 
+       // Wait for startNanotime != endNanotime. On Windows the default interval between
+       // system clock ticks is typically between 1 and 15 milliseconds, which may not
+       // have passed since the trace started. Without nanotime moving forward, trace
+       // tooling has no way of identifying how much real time each cputicks time deltas
+       // represent.
        for {
                trace.endTime = traceClockNow()
                trace.endTicks = cputicks()
                trace.endNanotime = nanotime()
-               // Windows time can tick only every 15ms, wait for at least one tick.
-               if trace.endNanotime != trace.startNanotime {
+
+               if trace.endNanotime != trace.startNanotime || faketime != 0 {
                        break
                }
                osyield()