Ensured network socket is closed neatly on exit