aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mgc.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2019-11-22 16:34:16 +0000
committerMichael Knyszek <mknyszek@google.com>2019-11-22 17:33:48 +0000
commit05511a5c0ae238325c10b0e4e44c3f66f928e4cf (patch)
tree87a477a26da874eee1827dcedbf30de02164be34 /src/runtime/mgc.go
parent1c5bd3459b2dfca44e4d313b49b525a26e38c181 (diff)
downloadgo-05511a5c0ae238325c10b0e4e44c3f66f928e4cf.tar.gz
go-05511a5c0ae238325c10b0e4e44c3f66f928e4cf.zip
runtime: release worldsema before Gosched in STW GC mode
After CL 182657 we no longer hold worldsema across the GC, we hold gcsema instead. However in STW GC mode we don't release worldsema before calling Gosched on the user goroutine (note that user goroutines are disabled during STW GC) so that user goroutine holds onto it. When the GC is done and the runtime inevitably wants to "stop the world" again (though there isn't much to stop) it'll sit there waiting for worldsema which won't be released until the aforementioned goroutine is scheduled, which it won't be until the GC is done! So, we have a deadlock. The fix is easy: just release worldsema before calling Gosched. Fixes #34736. Change-Id: Ia50db22ebed3176114e7e60a7edaf82f8535c1b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/208379 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/mgc.go')
-rw-r--r--src/runtime/mgc.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go
index 0bc5568442..bda8eadc9d 100644
--- a/src/runtime/mgc.go
+++ b/src/runtime/mgc.go
@@ -1368,6 +1368,13 @@ func gcStart(trigger gcTrigger) {
work.pauseNS += now - work.pauseStart
work.tMark = now
})
+
+ // Release the world sema before Gosched() in STW mode
+ // because we will need to reacquire it later but before
+ // this goroutine becomes runnable again, and we could
+ // self-deadlock otherwise.
+ semrelease(&worldsema)
+
// In STW mode, we could block the instant systemstack
// returns, so don't do anything important here. Make sure we
// block rather than returning to user code.
@@ -1375,7 +1382,6 @@ func gcStart(trigger gcTrigger) {
Gosched()
}
- semrelease(&worldsema)
semrelease(&work.startSema)
}