Revert "Handle premature socket termination"

This reverts commit 3bd8d62d6d45da132233ee20db1e3df3c9d312a8.
Revert "Revert "Handle premature socket termination""

This reverts commit 56b3608c89218e0dbdc144225a10e21691b1b459.