Files
mgmt/util
Kevin Kuehler 5d0efce278 engine: lang: util: Kill race in socketset
After some investigation, it appears that SocketSet.Shutdown() and
SocketSet.Close() are not synchronous operations. The sendto system call
called in SocketSet.Shutdown() is not a blocking send. That means there
is a race in which SocketSet.Shutdown() sends a message to a file
descriptor to unblock select, while SocketSet.Close() will close the
file descriptor that the message is being sent to. If SocketSet.Close()
wins the race, select is listening on a dead file descriptor and will
hang indefinitely.

This is fixed in the current master by putting SocketSet.Close() inside
of the goroutine in which data from the socket is being received. It
relies on SocketSet.Shutdown() being called to terminate the goroutine.
While this works most of the time, there is a race here. All the
goroutines can also be terminated by a closeChan. If the goroutine
receives an event (thus unblocking select) and then closeChan is
triggered, both SocketSet.Shutdown() and SocketSet.Close() race, leading
to undefined behavior.

This patch ensures the ordering of the two function calls by pulling
them both out of the goroutine and separating them with a WaitGroup.

Co-authored-by: James Shubin <james@shubin.ca>
2019-01-22 20:59:17 -08:00
..
2018-01-03 21:22:07 -05:00
2018-12-21 06:22:12 -05:00
2018-04-19 01:10:58 -04:00
2018-12-21 06:22:12 -05:00
2018-04-19 01:10:58 -04:00
2018-01-03 21:22:07 -05:00
2018-04-19 01:10:58 -04:00
2018-12-19 12:29:44 -05:00
2018-12-21 06:22:12 -05:00
2018-12-21 06:22:12 -05:00