<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
I wonder if those locks are the cause of the hangs I'm getting. Do
they have timers on them, or will they wait forever?<br>
<br>
Greg<br>
<br>
<br>
<div class="moz-cite-prefix">Mark Webb-Johnson wrote:<br>
</div>
<blockquote type="cite"
cite="mid:1358F917-D8B3-4554-BA9C-BB933C8FCB7C@webb-johnson.net">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Messy. The issue is the restarting of mdns, coupled with AP/STA
coming up/down in different threads. That could result in a
mdns_free while another mdns_free or mdns_init is in progress. The
mdns library is not thread safe. In particular, they mutex protect
some internal stuff but not all of mdns_free or any of mdns_init.
<div class=""><br class="">
</div>
<div class="">I introduced an ovms_mutex library to main. This
contains some helpful wrapper functions to make mutexes easy and
safe to use:</div>
<div class=""><br class="">
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">
<div class="">class OvmsMutex</div>
</blockquote>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">
<div class="">Encapsulates a mutex.</div>
<div class="">Provides Lock() and Unlock() functions to access
it.</div>
</blockquote>
<br class="">
</blockquote>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">class OvmsMutexLock</blockquote>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">Encapsulates a mutex lock in a safer manner.</blockquote>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">Constructor locks it, and destructor unlocks
it.</blockquote>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">Using this is as simple as creating a mutex for
the object to be protected, and then creating a
OvmsMutexLock(&mutex) over that. When the OvmsMutexLock
comes in scope, it will lock the mutex, and when it goes out
of scope it will unlock it.</blockquote>
<br class="">
</blockquote>
<blockquote style="margin: 0 0 0 40px; border: none; padding:
0px;" class="">I’ve done this in other projects, with great
success. Using OvmsMutexLock objects means you never forget to
unlock the mutex (no matter how weird and wonderful your code
paths are).</blockquote>
<div class="">
<div class=""><br class="">
</div>
<div class="">I then used OvmsMutex and OvmsMutexLock in
ovms_mdns. The mdns stuff seems ok for me now.</div>
<div class=""><br class="">
</div>
<div class="">Regards, Mark.<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 19 Mar 2018, at 9:51 AM, Mark
Webb-Johnson <<a href="mailto:mark@webb-johnson.net"
class="" moz-do-not-send="true">mark@webb-johnson.net</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class=""><br class="">
It seems that mdns_free is being called, while
mdns_free is running…<br class="">
<br class="">
It is trivial to fix it in the timer deletion code,
but that just delays the problem until a bit later
(the hostname free).<br class="">
<br class="">
I am looking at this now.<br class="">
<br class="">
Regards, Mark.<br class="">
<br class="">
<blockquote type="cite" class="">On 19 Mar 2018, at
9:40 AM, Stephen Casner <<a
href="mailto:casner@acm.org" class=""
moz-do-not-send="true">casner@acm.org</a>>
wrote:<br class="">
<br class="">
On Sun, 18 Mar 2018, Michael Balzer wrote:<br
class="">
<br class="">
<blockquote type="cite" class="">From a first look
at the mdns code in your backtrace, I would guess<br
class="">
that's a double free() for the timer, it seems the
timer_handle<br class="">
never gets NULLed.<br class="">
</blockquote>
<br class="">
That may be a bug (deficiency) in the esp-idf mDNS
code.<br class="">
<br class="">
Perhaps I hit it because OvmsMDNS::StopMDNS was
called without<br class="">
everything coming up correctly first?<br class="">
<br class="">
-- Steve<br
class="">
_______________________________________________<br
class="">
OvmsDev mailing list<br class="">
<a href="mailto:OvmsDev@lists.teslaclub.hk" class=""
moz-do-not-send="true">OvmsDev@lists.teslaclub.hk</a><br
class="">
<a class="moz-txt-link-freetext" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a><br
class="">
</blockquote>
<br class="">
_______________________________________________<br
class="">
OvmsDev mailing list<br class="">
<a href="mailto:OvmsDev@lists.teslaclub.hk" class=""
moz-do-not-send="true">OvmsDev@lists.teslaclub.hk</a><br
class="">
<a class="moz-txt-link-freetext" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a><br
class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
OvmsDev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:OvmsDev@lists.teslaclub.hk">OvmsDev@lists.teslaclub.hk</a>
<a class="moz-txt-link-freetext" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a>
</pre>
</blockquote>
<br>
</body>
</html>