reloadware / reloadium

Hot Reloading and Profiling for Python
https://reloadium.io
Apache License 2.0
2.74k stars 56 forks source link

pydevd_process_net_command.py this file frequently wrong as UnicodeDecodeError #183

Open fangplu opened 4 months ago

fangplu commented 4 months ago

def _on_run(self): read_buffer = "" try:

        while not self.killReceived:
            try:
                r = self.sock.recv(1024)
            except:
                if not self.killReceived:
                    traceback.print_exc()
                    self.handle_except()
                return #Finished communication.

            #Note: the java backend is always expected to pass utf-8 encoded strings. We now work with unicode
            #internally and thus, we may need to convert to the actual encoding where needed (i.e.: filenames
            #on python 2 may need to be converted to the filesystem encoding).
            if hasattr(r, 'decode'):

                r = r.decode('utf-8')

            read_buffer += r
            if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS:
                sys.stderr.write(u'debugger: received >>%s<<\n' % (read_buffer,))
                sys.stderr.flush()

            if len(read_buffer) == 0:
                self.handle_except()
                break
            while read_buffer.find(u'\n') != -1:
                command, read_buffer = read_buffer.split(u'\n', 1)

                args = command.split(u'\t', 2)
                try:
                    cmd_id = int(args[0])
                    pydev_log.debug('Received command: %s %s\n' % (ID_TO_MEANING.get(str(cmd_id), '???'), command,))
                    self.process_command(cmd_id, int(args[1]), args[2])
                except:
                    traceback.print_exc()
                    sys.stderr.write("Can't process net command: %s\n" % command)
                    sys.stderr.flush()

    except:
        traceback.print_exc()
        self.handle_except()

When starting debugging frequently wrong show : r = r.decode('utf-8') ^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data