[X-Protocol] struct.error: unpack requires a buffer of xxx bytes while reading
While trying to communicate with NV-CONTROL using the X-Protocol implementation form minx.py, an error similar to this might show up:
nvctrl.py:5343 2019-01-12 14:09:55,978: ERROR/ThreadPoolExecutor-1_2(21986) Try #0 failed.
Traceback (most recent call last):
File "/home/leinardi/Workspace/gitlab/gwe/gwe/nvidia/nvctrl.py", line 5338, in query_string_attribute
reply = NVCtrlQueryStringAttributeReply(binrp)
File "/home/leinardi/Workspace/gitlab/gwe/gwe/nvidia/nvctrl.py", line 5064, in __init__
rs, ad = minx.decode(ad, XData('STRING8', self.n, 'string'))
File "/home/leinardi/Workspace/gitlab/gwe/gwe/nvidia/minx.py", line 132, in decode
result_dict[arg.value] = struct.unpack(structcode, data[:size])[0]
struct.error: unpack requires a buffer of 1220 bytes
nvctrl.py:5343 2019-01-12 14:09:55,989: ERROR/ThreadPoolExecutor-1_2(21986) Try #1 failed.
Traceback (most recent call last):
File "/home/leinardi/Workspace/gitlab/gwe/gwe/nvidia/nvctrl.py", line 5338, in query_string_attribute
reply = NVCtrlQueryStringAttributeReply(binrp)
File "/home/leinardi/Workspace/gitlab/gwe/gwe/nvidia/nvctrl.py", line 5064, in __init__
rs, ad = minx.decode(ad, XData('STRING8', self.n, 'string'))
File "/home/leinardi/Workspace/gitlab/gwe/gwe/nvidia/minx.py", line 132, in decode
result_dict[arg.value] = struct.unpack(structcode, data[:size])[0]
struct.error: unpack requires a buffer of 1030447984 bytes
Findings so far:
- it mostly happens when reading strings (
NVCtrlQueryStringAttributeReply
) but can happen also with other types - it is not 100% reproducible and the current code tries to minimize its occurrence by reducing to the minimum the invocations of
NVCtrlQueryStringAttributeReply
- when the error happens, the next query seems to get the previous answer
- it is probably due to me doing a bad port from Python2 to Python3 of the origina X-Protocol implementation (sorry guys, I'm an Android dev and just started with Python)
- it can be easily reproduced using the branch feature/struct-error and executing the
run
script on the root of the project.
Since my current knowledge of Python and X-Protocol is not that good I would really appreciate some help with this issue.