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

Python function DomsticzEx.Register fails on startup #5379

Closed
e-v-k opened this issue Oct 28, 2022 · 3 comments
Closed

Python function DomsticzEx.Register fails on startup #5379

e-v-k opened this issue Oct 28, 2022 · 3 comments

Comments

@e-v-k
Copy link

e-v-k commented Oct 28, 2022

docker:latest
Domoticz V2022.1 (build 14580) (c)2012-2022 GizMoCuz
Build Hash: b7f96c8, Date: 2022-10-19 15:52:59
Python version '3.7.3'

git development branch
b7f96c8
Python version '3.9.2'

Description
Adding a call to DomoticzEx.Register() in a python plugin causes a crash at startup (see log further down). This will only occur during Domoticz start. Adding the plugin and disable/enable works fine.

This is caused by PyDomoticz_Register() trying to return Py_RETURN_NONE before the Py_None object is created. Changing the return to
return Py_BuildValue(""); seems to fix the problem. But I don't have enough experience of Domoticz or the Python API to say if this is correct.

With this change I get the following error on exit

2022-10-28 12:28:13.670  Error: Stop: Unit 'Dimmer' Reference Count not one: 2.
2022-10-28 12:28:13.671  Error: regtest: Stop: Device 'Dimmer' Reference Count not correct, expected 1 found 3.

I suspect that this is an additional error, but could also be caused by my fix.

Information from log on Domoticz start

domoticz    | 2022-10-28 14:21:21.120  Test: Worker thread started.
domoticz    | 2022-10-28 14:21:21.120  Status: Test: Started.
domoticz    | 2022-10-28 14:21:21.120  Status: Test: Entering work loop.
domoticz    | 2022-10-28 14:21:21.121  Status: NotificationSystem: thread started...
domoticz    | 2022-10-28 14:21:21.121  Status: EventSystem: reset all events...
domoticz    | 2022-10-28 14:21:21.122  Status: EventSystem: reset all device statuses...
domoticz    | 2022-10-28 14:21:21.159  Status: Python EventSystem: Initializing event module.
domoticz    | 2022-10-28 14:21:21.159  Status: EventSystem: Started
domoticz    | 2022-10-28 14:21:21.159  Status: EventSystem: Queue thread started...
domoticz    | Fatal Python error: Segmentation fault
domoticz    | 
domoticz    | Current thread 0x00007fd07a7fc700 (most recent call first):
domoticz    |   File "/opt/domoticz/userdata/plugins/test/plugin.py", line 70 in <module>
domoticz    |   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
domoticz    |   File "<frozen importlib._bootstrap_external>", line 728 in exec_module
domoticz    |   File "<frozen importlib._bootstrap>", line 677 in _load_unlocked
domoticz    |   File "<frozen importlib._bootstrap>", line 967 in _find_and_load_unlocked
domoticz    |   File "<frozen importlib._bootstrap>", line 983 in _find_and_load
domoticz    | 2022-10-28 14:21:21.215  Error: Domoticz(pid:1, tid:20('Test')) received fatal signal 11 (Segmentation fault)
domoticz    | 2022-10-28 14:21:21.215  Error: siginfo address=0x1, address=0x7fd08eb1f5cb
domoticz    | 2022-10-28 14:21:21.219  Error: Failed to start gdb, will use backtrace() for printing stack frame
domoticz    | 
domoticz    | 2022-10-28 14:21:21.221  Error: #0  /opt/domoticz/domoticz :  + 0x3b9dc3 [0x55c6bf1a5dc3]
domoticz    | 2022-10-28 14:21:21.221  Error: #1  /opt/domoticz/domoticz : signal_handler(int, siginfo_t*, void*) + 0x205 [0x55c6bf1a6825]
domoticz    | 2022-10-28 14:21:21.221  Error: #2  /lib/x86_64-linux-gnu/libpthread.so.0 :  + 0x12730 [0x7fd08eb1f730]
domoticz    | 2022-10-28 14:21:21.221  Error: #3  /lib/x86_64-linux-gnu/libpthread.so.0 : raise + 0x10b [0x7fd08eb1f5cb]
domoticz    | 2022-10-28 14:21:21.221  Error: #4  /lib/x86_64-linux-gnu/libpthread.so.0 :  + 0x12730 [0x7fd08eb1f730]
domoticz    | 2022-10-28 14:21:21.221  Error: #5  /opt/domoticz/domoticz :  + 0x7a60e5 [0x55c6bf5920e5]
domoticz    | 2022-10-28 14:21:21.221  Error: #6  /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyMethodDef_RawFastCallKeywords + 0x18b [0x7fd08d7b4b5b]
domoticz    | 2022-10-28 14:21:21.221  Error: #7  /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyCFunction_FastCallKeywords + 0x25 [0x7fd08d7b5a05]
domoticz    | 2022-10-28 14:21:21.221  Error: #8  /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalFrameDefault + 0x8293 [0x7fd08d5b70b3]
domoticz    | 2022-10-28 14:21:21.221  Error: #9  /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalCodeWithName + 0x996 [0x7fd08d6de1e6]
domoticz    | 2022-10-28 14:21:21.221  Error: #10 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : PyEval_EvalCodeEx + 0x3e [0x7fd08d6de46e]
domoticz    | 2022-10-28 14:21:21.221  Error: #11 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : PyEval_EvalCode + 0x1b [0x7fd08d6df23b]
domoticz    | 2022-10-28 14:21:21.221  Error: #12 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x1a2bdd [0x7fd08d6e2bdd]
domoticz    | 2022-10-28 14:21:21.221  Error: #13 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyMethodDef_RawFastCallDict + 0x1d7 [0x7fd08d7b4f37]
domoticz    | 2022-10-28 14:21:21.221  Error: #14 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyCFunction_FastCallDict + 0x25 [0x7fd08d7b5a45]
domoticz    | 2022-10-28 14:21:21.221  Error: #15 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalFrameDefault + 0x78e0 [0x7fd08d5b6700]
domoticz    | 2022-10-28 14:21:21.221  Error: #16 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalCodeWithName + 0x996 [0x7fd08d6de1e6]
domoticz    | 2022-10-28 14:21:21.222  Error: #17 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyFunction_FastCallKeywords + 0x93 [0x7fd08d7b5123]
domoticz    | 2022-10-28 14:21:21.222  Error: #18 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalFrameDefault + 0x7b95 [0x7fd08d5b69b5]
domoticz    | 2022-10-28 14:21:21.222  Error: #19 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x794d3 [0x7fd08d5b94d3]
domoticz    | 2022-10-28 14:21:21.222  Error: #20 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalFrameDefault + 0x9334 [0x7fd08d5b8154]
domoticz    | 2022-10-28 14:21:21.222  Error: #21 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x794d3 [0x7fd08d5b94d3]
domoticz    | 2022-10-28 14:21:21.222  Error: #22 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalFrameDefault + 0x5d1c [0x7fd08d5b4b3c]
domoticz    | 2022-10-28 14:21:21.222  Error: #23 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x794d3 [0x7fd08d5b94d3]
domoticz    | 2022-10-28 14:21:21.222  Error: #24 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyEval_EvalFrameDefault + 0x5d1c [0x7fd08d5b4b3c]
domoticz    | 2022-10-28 14:21:21.222  Error: #25 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x794d3 [0x7fd08d5b94d3]
domoticz    | 2022-10-28 14:21:21.222  Error: #26 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyFunction_FastCallDict + 0x2e2 [0x7fd08d7b5542]
domoticz    | 2022-10-28 14:21:21.222  Error: #27 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x276d60 [0x7fd08d7b6d60]
domoticz    | 2022-10-28 14:21:21.222  Error: #28 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyObject_CallMethodIdObjArgs + 0xa9 [0x7fd08d7b7389]
domoticz    | 2022-10-28 14:21:21.222  Error: #29 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : PyImport_ImportModuleLevelObject + 0x60f [0x7fd08d5c183f]
domoticz    | 2022-10-28 14:21:21.222  Error: #30 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x1a11d8 [0x7fd08d6e11d8]
domoticz    | 2022-10-28 14:21:21.222  Error: #31 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyMethodDef_RawFastCallDict + 0x13b [0x7fd08d7b4e9b]
domoticz    | 2022-10-28 14:21:21.222  Error: #32 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : _PyCFunction_FastCallDict + 0x25 [0x7fd08d7b5a45]
domoticz    | 2022-10-28 14:21:21.222  Error: #33 /usr/lib/x86_64-linux-gnu/libpython3.7m.so :  + 0x276bfb [0x7fd08d7b6bfb]
domoticz    | 2022-10-28 14:21:21.222  Error: #34 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : PyObject_CallFunction + 0x9b [0x7fd08d7b80db]
domoticz    | 2022-10-28 14:21:21.222  Error: #35 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : PyImport_Import + 0x9a [0x7fd08d6c3faa]
domoticz    | 2022-10-28 14:21:21.222  Error: #36 /usr/lib/x86_64-linux-gnu/libpython3.7m.so : PyImport_ImportModule + 0x1a [0x7fd08d6c419a]
domoticz    | 2022-10-28 14:21:21.222  Error: #37 /opt/domoticz/domoticz : Plugins::CPlugin::Initialise() + 0x742 [0x55c6bf59cbb2]
domoticz    | 2022-10-28 14:21:21.222  Error: #38 /opt/domoticz/domoticz : Plugins::CPlugin::Do_Work() + 0x43b [0x55c6bf59eeeb]
domoticz    | 2022-10-28 14:21:21.222  Error: #39 /opt/domoticz/domoticz :  + 0xa346bf [0x55c6bf8206bf]
domoticz    | 2022-10-28 14:21:21.222  Error: #40 /lib/x86_64-linux-gnu/libpthread.so.0 :  + 0x7fa3 [0x7fd08eb14fa3]
domoticz    | 2022-10-28 14:21:21.222  Error: #41 /lib/x86_64-linux-gnu/libc.so.6 : clone + 0x3f [0x7fd08e89a06f]
@e-v-k
Copy link
Author

e-v-k commented Oct 28, 2022

plugin.txt
This is the plugin that is used. It's just the base example with Register function copied from documentation.

(Renamed to .txt to make github happy)

@dnpwwo
Copy link
Contributor

dnpwwo commented Oct 28, 2022

@e-v-k,

This crash appears to be an accidental side effect of the change to the Plugin Framework to use Python's global 'None' value rather than having it's own. Turned out that Domoticz having its own 'None' caused 'None' comparisons to fail inside plugin functions which isn't great.

I will push a fix where the the Plugin Framework gets a reference to the global None prior to importing the plugin which will resolve this.

@e-v-k
Copy link
Author

e-v-k commented Oct 29, 2022

Yes, that fixed the problem. Great work.

Still wrong reference count on exit, but that didn't seem related to this. I'll open a new issue for that as soon as I've had time to investigate.

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