]> Cypherpunks repositories - gostls13.git/commit
runtime: fix sudog leak
authorRuss Cox <rsc@golang.org>
Sun, 16 Nov 2014 21:44:45 +0000 (16:44 -0500)
committerRuss Cox <rsc@golang.org>
Sun, 16 Nov 2014 21:44:45 +0000 (16:44 -0500)
commitb3932baba4e15e175e8f0e040d5e8bbd357a60d8
tree6581292fde524f2196fc1a00c7ee888db28adf70
parent6150414cb8819ab9f054298ec7f8006a43ab8eea
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 #9110.

LGTM=r
R=r
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/177870043
src/runtime/chan.go
src/runtime/mgc0.go
src/runtime/proc.go
src/runtime/select.go
src/runtime/sema.go
test/fixedbugs/issue9110.go [new file with mode: 0644]