Fixed dead lock in shutdown, issue 285