Be more vigilant about closing sockets on errors