TRQ-1023. Some of our socket handling code wasn't checking errors correctly. Fix this.