Ensure sockets are closed after use