Gracefully close connections on exit