4kux / winsvc

Automatically exported from code.google.com/p/winsvc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

winsvc/svc: deadlock between package and client code #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
from https://groups.google.com/d/msg/golang-nuts/ArQH2CjwXh8/azMGg9VPs-EJ

>>>
The problem manifests as a deadlock between the loop at 
bitbucket.org/kardianos/service/service_windows.go:35 (call this loop K) and 
the loop at code.google.com/p/winsvc/svc/service.go:206 (call this loop B).

If Windows sends multiple service commands to B quickly enough the deadlock can 
be triggered. It occurs like this: B receives a command from Windows and case r 
of its select is taken, so B sends a ChangeRequest to K on an unbuffered 
channel. K receives the command and sends a status update back to B. If, in the 
mean time Windows sends another command to B, then B can select to receive 
either the status update from K or the new command from the OS. If it chooses 
the command it will deadlock because B is blocked sending to K, and K is 
blocked sending to B and neither loop is ready to receive.

The choice of which package to patch depends on how we interpret the 
responsibilities of the two packages as they communicate. But personally I 
think the channel send at B:216 is wrong and needs to be part of the outer 
select statement instead of a stand alone synchronous channel send.
<<<

Alex

Original issue reported on code.google.com by alex.bra...@gmail.com on 20 May 2014 at 12:26

GoogleCodeExporter commented 8 years ago
A fix https://codereview.appspot.com/100660046/

Alex

Original comment by alex.bra...@gmail.com on 22 May 2014 at 1:59

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 55c219787944.

Original comment by alex.bra...@gmail.com on 22 May 2014 at 4:46