Hi, On 07/20/2013 10:07 PM, Chris Dickens wrote: > Hi, > > This patch does indeed fix the deadlock condition on libusb_exit(), but > unfortunately it opens up another opportunity for deadlock :( > > If the hotplug event thread is processing a hotplug event when it is > cancelled, there is a chance that it may be cancelled while holding the > active_contexts_lock (inside linux_hotplug_enumerate() or > linux_hotplug_disconnected()). Granted this is a very small chance, because > the active_contexts_list should be empty when the hotplug event thread is > being shut down, but it is possible nonetheless. If this occurs, libusb will > be unusable from that point forward, since the active_contexts_lock is > static. If the application is exiting, no big deal--otherwise, the next call > to libusb_init() will hang.
You're right, but the problem is not only with leaving active_contexts_lock locked, but the race can also leave the linux_hotplug_lock locked, and the chances of that happening are much greater. Actually the user hitting the original problem, is now hitting exactly this, see: https://bugzilla.redhat.com/show_bug.cgi?id=985484 And esp: https://bugzilla.redhat.com/attachment.cgi?id=778202 > The only robust solution would be to gracefully end the hotplug event thread. > This can be achieved using the control pipe approach that Toby Gray provided > for netlink. pthread_cancel() is in general not very graceful, so I think it > would do well to eliminate it. > > The attached patch, in conjunction with your patch to use two separate locks, > should eliminate issues surrounding this. Thanks, the sizeof(fds) is not a good idea though, as that gives the size in bytes rather then array elements, leading to poll doing stack smashing and segfaults. I've just pushed my original patch for this + a fixed version of your patch, as well as similar patches for the netlink code paths to master. Together these patches should fix all the deadlock issues, so I believe we should do a 1.0.17-rc1 soon, and then onto 1.0.17 to get these fixes out there. Regards, Hans ------------------------------------------------------------------------------ Get your SQL database under version control now! Version control is standard for application code, but databases havent caught up. So what steps can you take to put your SQL databases under version control? Why should you start doing it? Read more to find out. http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk _______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel