canonical / pebble

Take control of your internal daemons!
GNU General Public License v3.0
137 stars 52 forks source link

fix(servstate): don't hold both servicesLock and state lock at once #359

Closed benhoyt closed 5 months ago

benhoyt commented 5 months ago

This avoids the 3-lock deadlock described in https://github.com/canonical/pebble/issues/314. Other goroutines may be holding the state lock and waiting for the services lock, so it's problematic to acquire both locks at once. Break that part of the cycle.

We could do this inside serviceForStart/serviceForStop by manually calling Unlock() sooner, but that's error-prone, so continue using defer, but have the caller write the task log (which needs the state lock) after the services lock is released.

This is in preference to the more invasive change in https://github.com/canonical/pebble/pull/356