Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async serial crc check may hang #2606

Open
dcneeme opened this issue Mar 12, 2025 · 5 comments
Open

async serial crc check may hang #2606

dcneeme opened this issue Mar 12, 2025 · 5 comments

Comments

@dcneeme
Copy link

dcneeme commented Mar 12, 2025

ubuntu 20.4 on arm, python3.9, pymodbus 3.8.2

got stuck into CRC calculation (pymodbus/framer/rtu.py)? 100% CPU, everything frozen. happens daily under heavy load.

(venv_pymodbus3) root@K20kyte:~/pyapp# py-spy dump --pid 82492
Process 82492: python3 /root/pyapp/iomain3.py
Python v3.9.5 (/usr/bin/python3.9)

Thread 0x7F7D26E010 (active+gil): "MainThread"
compute_CRC (pymodbus/framer/rtu.py:156)
check_CRC (pymodbus/framer/rtu.py:142)
decode (pymodbus/framer/rtu.py:122)
_processIncomingFrame (pymodbus/framer/base.py:94)
processIncomingFrame (pymodbus/framer/base.py:76)
callback_data (pymodbus/transaction/transaction.py:187)
datagram_received (pymodbus/transport/transport.py:338)
data_received (pymodbus/transport/transport.py:304)
intern_read_ready (pymodbus/transport/serialtransport.py:134)
_run (asyncio/events.py:80)
_run_once (asyncio/base_events.py:1890)
run_forever (asyncio/base_events.py:596)
run_until_complete (asyncio/base_events.py:629)
(iomain3.py:345)
Thread 0x7F6E05A1E0 (active): "asyncio_0"
_worker (concurrent/futures/thread.py:75)
run (threading.py:892)
_bootstrap_inner (threading.py:954)
_bootstrap (threading.py:912)

@janiversen
Copy link
Collaborator

Please add a debug log as pr issue template, so we can see the frame causing the problem.

Without knowing the frame, we have no idea what the problem might be...there are no infinite loops in the crc calculation.

@janiversen
Copy link
Collaborator

janiversen commented Mar 12, 2025

This is the loop:


for data_byte in data:
            idx = cls.crc16_table[(crc ^ int(data_byte)) & 0xFF]
            crc = ((crc >> 8) & 0xFF) ^ idx

it is hard to see how that can cause a system to freeze, unless there was some really big data was received.

Also you are using an old version v3.8.6 is the latest, but I am not sure there are no changes relevant to your problem.

@janiversen
Copy link
Collaborator

It is more likely that the problem is not in the crc calculation but that pymodbus receives data continuously, a debug log will show thst clearly.

@dcneeme
Copy link
Author

dcneeme commented Mar 12, 2025

i never send another request before a response or timeout is received.
i'll try to catch the debug log, it may be a bit difficult.

@janiversen
Copy link
Collaborator

janiversen commented Mar 12, 2025

pymodbus have a simple call to activate the debug log the rest is just redirecting the output.

And if it's the first and only request, it should be easy to catch.

Anyhow without a debug log it is quite impossible to help.

Did you try to run the spy multiple times fast, to see if pymodbus is really stuck in crc or it's a bigger loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants