fix shutdown token not exiting worker loop and improve ordering of shutdown operations