[vlc-devel] [PATCH v6 3/7] upnp: Split s_lock into two locks to solve deadlock issue

Rémi Denis-Courmont remi at remlab.net
Sat Dec 7 19:39:23 CET 2019


Whether this might race or not depends on what thread safety guaranties libupnp provides, if any.

The fact that there is a lock is a strong hint that it provides none, and if so, it must be operated under a unique lock.

Le 6 décembre 2019 20:50:20 GMT+01:00, Johan Gunnarsson <johan.gunnarsson at gmail.com> a écrit :
>Den ons 4 dec. 2019 kl 21:56 skrev Rémi Denis-Courmont
><remi at remlab.net>:
>>
>> Le keskiviikkona 4. joulukuuta 2019, 22.39.59 EET Johan Gunnarsson a
>écrit :
>> > If libupnp executes a callback while vlc runs UpnpInstanceWrapper
>dtor, vlc
>> > will deadlock. This happens because the callback handler and
>> > UpnpInstanceWrapper dtor both takes s_lock, and Upnp_Finish waits
>for all
>> > callbacks to finish. UpnpUnRegisterRootDevice causes libupnp to
>broadcast
>> > "byebye" advertisements, which libupnp picks up again and delivers
>as
>> > callbacks.
>> >
>> > This patch separates the locks into one that protects the
>> > UpnpInstanceWrapper refcounts and one that protects the list of
>listeners.
>>
>> AFAICT, an UPnP instance as a whole is not thread-safe, so you cannot
>split
>> locks without inducing races inside the library.
>
>Not quite sure which code paths can race. Can you enlighten me? My
>point is I can't hold s_lock_listeners while calling UpnpFinish. That
>will deadlock.
>
>Maybe I can take s_lock_listeners in UpnpInstanceWrapper::get,
>UpnpInstanceWrapper::startMediaRenderer,
>UpnpInstanceWrapper::stopMediaRenderer and
>UpnpInstanceWrapper::~UpnpInstanceWrapper, but release it right before
>UpnpFinish?
>
>>
>> --
>> Rémi Denis-Courmont
>> http://www.remlab.net/
>>
>>
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20191207/5c355868/attachment.html>


More information about the vlc-devel mailing list