`socket.close()` should IMO go into a `finally` section.