fix hanging script due to unclosed connections