Repository navigation
get_tree() crashes with a JSON decode error #175
Copy link
Copy link
Closed
Labels
Description
I have been experimenting with one of your examples and I keep getting a JSON decode error triggered by a call to aio.Con.get_tree(). Here is a paired down snippet that triggers the issue:
#!/usr/bin/env python3
import asyncio
import logging
from i3ipc.aio import Connection
SOCKET_FILE = '/tmp/.i3-cycle-focus.sock'
class FocusWatcher:
def __init__(self):
self.i3 = None
async def connect(self):
self.i3 = await Connection().connect()
self.i3.on('window::focus', self.on_window_focus)
async def on_window_focus(self, i3conn, event):
logging.info('got window focus event')
tree = await self.i3.get_tree()
async def run(self):
async def handle_switch(reader, writer):
data = await reader.read(1024)
logging.info('received data: {}').format(data)
server = await asyncio.start_unix_server(handle_switch, SOCKET_FILE)
await server.serve_forever()
async def run_server():
focus_watcher = FocusWatcher()
await focus_watcher.connect()
await focus_watcher.run()
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
asyncio.run(run_server())
here is an example log output:
... (normal looking long json representing the tree)...
x":0,"y":0,"width":0,"height":0},"geometry":{"x":0,"y":0,"width":0,"height":0},"name":"25","num":25,"window":null,"window_type":null,"nodes":[{"id":94793549'
INFO:i3ipc.aio.connection:quitting the main loop
Traceback (most recent call last):
File "/home/epenn/code/i3ipc-python/.env/lib/python3.8/site-packages/i3ipc-2.2.1-py3.8.egg/i3ipc/aio/connection.py", line 37, in handler_coroutine
await handler(conn, data)
File "examples/bug.py", line 27, in on_window_focus
tree = await self.i3.get_tree()
File "/home/epenn/code/i3ipc-python/.env/lib/python3.8/site-packages/i3ipc-2.2.1-py3.8.egg/i3ipc/aio/connection.py", line 628, in get_tree
return Con(json.loads(data), None, self)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 36519 (char 36518)
As you can see, the json message is truncated, causing a decode error. To reproduce this behavior, it is necessary to run the script and then change focus (triggering the get_tree call). It will take sometimes ~5 focus events to trigger, other times hundreds.
Reactions are currently unavailable
Activity
acrisci commentedon Feb 12, 2021
I think I would need to add some logging to investigate this.
jvasile commentedon Mar 15, 2021
I'm hitting this error when I get_tree() as well. What is interesting to me is that I get the json error at the same place: line 1, column 36519. The JSON string is getting truncated somewhere.
Relevant part of the stacktrace:
jvasile commentedon Mar 15, 2021
This appears to avoid the error:
haolian9 commentedon Jul 1, 2021
can anybody got this decode error provide a complete raw json responsed by i3wm/sway? using the following codes