More work on #894: Race condition at shutdown