Broken pipe errors

A bunch of fixes to reduce 'broken pipe' errors. These happen when the browser disconnects while closing a connection.