Add graceful shutdown of connections