fix loop shutdown issue