Bug: Traceback when a non-JSON payload is received #2

Closed
opened 2024-09-07 19:35:26 +00:00 by agatha · 0 comments
Owner

Describe the bug:
When the server receives a non-JSON payload the handler thread crashes with the following traceback:

2024-09-07 19:32:31.574 | INFO     | __main__:start:46 - Connection from ('172.17.0.1', 55548)
Exception in thread Thread-6 (handle_agent):
Traceback (most recent call last):
  File "/app/main.py", line 68, in handle_agent
    agent_info = json.loads(conn.recv(1024).decode())
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/app/main.py", line 87, in handle_agent
    logger.error(f"Error handling agent {agent_id}: {e}")
UnboundLocalError: local variable 'agent_id' referenced before assignment

Reproduction steps:

python -c 'print("A"*2048)' | nc localhost 9999
**Describe the bug**: When the server receives a non-JSON payload the handler thread crashes with the following traceback: ``` 2024-09-07 19:32:31.574 | INFO | __main__:start:46 - Connection from ('172.17.0.1', 55548) Exception in thread Thread-6 (handle_agent): Traceback (most recent call last): File "/app/main.py", line 68, in handle_agent agent_info = json.loads(conn.recv(1024).decode()) File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/local/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/app/main.py", line 87, in handle_agent logger.error(f"Error handling agent {agent_id}: {e}") UnboundLocalError: local variable 'agent_id' referenced before assignment ``` **Reproduction steps**: ``` python -c 'print("A"*2048)' | nc localhost 9999 ```
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: agatha/pyc2#2
No description provided.