summaryrefslogtreecommitdiff
path: root/src/runtime/mgc0.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-11-16 16:44:45 -0500
committerRuss Cox <rsc@golang.org>2014-11-16 16:44:45 -0500
commitca1e131f589cad741fda16c17155e9225ec9ec04 (patch)
tree90077f6987427eea0815aa1e4c52144780f5385e /src/runtime/mgc0.go
parent5005e63e270d757af01625b857450168f02585f9 (diff)
downloadgo-ca1e131f589cad741fda16c17155e9225ec9ec04.tar.gz
runtime: fix sudog leak
The SudoG used to sit on the stack, so it was cheap to allocated and didn't need to be cleaned up when finished. For the conversion to Go, we had to move sudog off the stack for a few reasons, so we added a cache of recently used sudogs to keep allocation cheap. But we didn't add any of the necessary cleanup before adding a SudoG to the new cache, and so the cached SudoGs had stale pointers inside them that have caused all sorts of awful, hard to debug problems. CL 155760043 made sure SudoG.elem is cleaned up. CL 150520043 made sure SudoG.selectdone is cleaned up. This CL makes sure SudoG.next, SudoG.prev, and SudoG.waitlink are cleaned up. I should have done this when I did the other two fields; instead I wasted a week tracking down a leak they caused. A dangling SudoG.waitlink can point into a sudogcache list that has been "forgotten" in order to let the GC collect it, but that dangling .waitlink keeps the list from being collected. And then the list holding the SudoG with the dangling waitlink can find itself in the same situation, and so on. We end up with lists of lists of unusable SudoGs that are still linked into the object graph and never collected (given the right mix of non-trivial selects and non-channel synchronization). More details in golang.org/issue/9110. Fixes issue 9110. LGTM=r R=r CC=dvyukov, golang-codereviews, iant, khr https://codereview.appspot.com/177870043
Diffstat (limited to 'src/runtime/mgc0.go')
-rw-r--r--src/runtime/mgc0.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime/mgc0.go b/src/runtime/mgc0.go
index 3a7204b54..cbf5e9cfd 100644
--- a/src/runtime/mgc0.go
+++ b/src/runtime/mgc0.go
@@ -51,10 +51,26 @@ func clearpools() {
if c := p.mcache; c != nil {
c.tiny = nil
c.tinysize = 0
+
+ // disconnect cached list before dropping it on the floor,
+ // so that a dangling ref to one entry does not pin all of them.
+ var sg, sgnext *sudog
+ for sg = c.sudogcache; sg != nil; sg = sgnext {
+ sgnext = sg.next
+ sg.next = nil
+ }
c.sudogcache = nil
}
+
// clear defer pools
for i := range p.deferpool {
+ // disconnect cached list before dropping it on the floor,
+ // so that a dangling ref to one entry does not pin all of them.
+ var d, dlink *_defer
+ for d = p.deferpool[i]; d != nil; d = dlink {
+ dlink = d.link
+ d.link = nil
+ }
p.deferpool[i] = nil
}
}