GNOME Bugzilla – Bug 794957
deadlock in g_vfs_daemon_close_active_channels
Last modified: 2018-04-13 08:28:39 UTC
Since the fix for bug 787992, g_vfs_daemon_close_active_channels will deadlock if there are any active channels. The function itself holds daemon->lock, and job_source_closed_callback will attempt to take it again. I can reproduce this reliably by suspending my laptop (fedora 27, gvfs 1.34.2.1) with an active sftp mount, then resuming several hours later. The ssh process(es) close and gvfsd-sftp then gets stuck here:
+ Trace 238532
Thanks for the report! Deadlock instead of segfault was not really intentional :-( I will try to prepare proper fix instead of just blind reversion of those patches...
It seems that the this is more complicated than it looks. This bug just points to another bug in this code, which was there before. Signals are synchronous and thus g_vfs_channel_force_close causes removal of the current list item from daemon->job_sources and consequently there is an invalid read on l->next...
Created attachment 370731 [details] [review] daemon: Prevent deadlock and invalid read when closing channels Commit e147e48 added missing mutex guards for job_sources, which may unfortunately lead to deadlock because g_vfs_channel_force_close synchronously calls g_vfs_job_source_closed which is also guarded by the same mutex. The deadlock reveals another bug which was in that code. The code iterates over job_sources list, but g_vfs_job_source_closed removes current element of the list, which leads to invalid reads and potentially to segfaults also. This patch tries to fix the both mentioned issues.
Attachment 370731 [details] pushed as d35bab6 - daemon: Prevent deadlock and invalid read when closing channels Going to push into affected stable branches as well...