Page 1 of 1

Segmentation fault onStop

Posted: Tuesday 13 June 2017 23:15
by moroen
Hi all,

I'm struggling with a intermittent segmentation fault when pushing the "Update" button in the hardware-page. I have a skeleton plugin (just showing the relevant parts, the rest is unchanged from the base template, except the plugin definition in the head):

Code: Select all

class BasePlugin:
    enabled = False

    coapAdaptor = None

    def __init__(self):
        return

    def onStart(self):
        Domoticz.Log("onStart called")

        self.CoapAdapter = Domoticz.Connection(Name="Main", Transport="TCP/IP", Protocol="JSON", Address="127.0.0.1", Port="1234")
        self.CoapAdapter.Connect()
        
    def onMessage(self, Connection, Data, Status, Extra):
        Domoticz.Log("onMessage called with data: {0}".format(Data))
        
     #snipp#
Adding it works fine, it connects to my server (a simple telnet-server that responds with a json greeting). When selecting the plugin in the hardware list and pressing "Update", sometimes it stops and restarts the plugin as expected and sometimes domoticz dies with a segmentation fault. It varies how many times I can "update" before it seg-faults, but sooner or later it will:

Code: Select all

2017-06-13 23:09:18.790  (Test) Initialized version 1.0.0, author 'moroen'
2017-06-13 23:09:18.791  (Test) onStart called
2017-06-13 23:09:18.791  PluginSystem: Starting I/O service thread.
2017-06-13 23:09:18.841  (Test) onConnect called
2017-06-13 23:09:18.841  (Test) onMessage called with data: b'{"status": "Ok", "action": "clientConnect", "version": "0.1"}'
2017-06-13 23:09:20.290  (Test) Exiting work loop...
2017-06-13 23:09:20.296  (Test) onDisconnect called
2017-06-13 23:09:20.297  (Test) onStop called
2017-06-13 23:09:20.299  Error: CPluginTransport: Base handleRead invoked for Hardware 2
2017-06-13 23:09:20.361  (Test) Stopped.
2017-06-13 23:09:20.428  (Test) Initialized version 1.0.0, author 'moroen'
2017-06-13 23:09:20.429  (Test) onStart called
2017-06-13 23:09:20.429  PluginSystem: Starting I/O service thread.
2017-06-13 23:09:20.479  (Test) onConnect called
2017-06-13 23:09:20.479  (Test) onMessage called with data: b'{"status": "Ok", "action": "clientConnect", "version": "0.1"}'
2017-06-13 23:09:22.085  (Test) onDisconnect called
2017-06-13 23:09:22.085  (Test) onStop called
Segmentation fault
Using the latest master branch, compiled on debian linux. I have noticed that on my development-machine (Mac), using python 3.6.1 I can update the plugin as many times as I like, but on my test-setup, using python 3.4.2, the seg-fault happens... :shock:

Regards,
M

Re: Segmentation fault onStop

Posted: Thursday 15 June 2017 4:21
by Dnpwwo
@moroen,

Thanks for posting this I've got follow up question help pin this issue down.
  • I know the crash is inside the Boost libraries and AFAIK this issue does not occur on Windows (which uses 1.63.0) but does on Linux (which uses 1.55.0), what version does your Mac build use?
  • Can you post or PM me your test script? I'm really interested in this line in your log:

    Code: Select all

    2017-06-13 23:09:20.299  Error: CPluginTransport: Base handleRead invoked for Hardware 2
    because it should never happen

Re: Segmentation fault onStop

Posted: Thursday 15 June 2017 9:03
by SweetPants
@Dnpwwo, maybe this is related to http://www.domoticz.com/forum/viewtopic.php?f=6&t=17836. I had to disable Python support to get ride of the message on shutdown.

Re: Segmentation fault onStop

Posted: Thursday 15 June 2017 10:20
by Dnpwwo
@SweetPants,

I believe I have found what the issue is (it triggered on Windows today for some reason so I could have a really good look at what every thread was doing).

I don't have a fix yet but I'm currently soak testing a version on Linux that is leaking memory (but not crashing) running an intense test plugin that used to crash within 2 minutes previously but now seems to run okay. Once I prove that I have found the issue I should be able to do a fix pretty quickly.

I would still like to see @moroen's script though because the 'handleRead' error in his log is not the same thing at all.

Re: Segmentation fault onStop

Posted: Thursday 15 June 2017 10:41
by moroen
Dnpwwo wrote:I would still like to see @moroen's script though because the 'handleRead' error in his log is not the same thing at all.
I'll send it to you as soon as I get home from work! :)

Regards,
M