Attempting to solve #894: Race condition at shutdown