Revert b3e4456b94661bce16269a48549e35cc9e217808 and catch UnicodeDecodeErrors when reading from the socket