file_manager: fix notification sync on fast machines

Desktop class PCs may exit the request before the inotify observer
gains control of the loop.  When the observer does gain control
it will immediately notify as the sync mutex is no longer held,
this can result in sending  the websocket notification before
the response has returned.  Delay all notifications by 5ms to prevent
this.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-02-22 15:42:07 -05:00
parent a02209443e
commit fce056e481
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 9 additions and 13 deletions

View File

@ -792,7 +792,7 @@ class FileManager:
except Exception:
pass
raise
return result
return result
def _parse_upload_args(self,
upload_args: Dict[str, Any]
@ -2144,23 +2144,19 @@ class InotifyObserver(BaseFileSystemObserver):
source_root, source_path)
result['source_item'] = {'path': src_rel_path, 'root': source_root}
key = f"{action}-{root}-{rel_path}"
if sync_fut is not None:
# Delay this notification so that it occurs after an item
logging.debug(f"Syncing notification: {full_path}")
self.event_loop.register_callback(
self._sync_with_request, result, sync_fut, key
)
else:
self.file_manager.cancel_notification(key)
self.server.send_event("file_manager:filelist_changed", result)
self.event_loop.create_task(
self._finish_notify(result, sync_fut, key)
)
async def _sync_with_request(
async def _finish_notify(
self,
result: Dict[str, Any],
sync_fut: asyncio.Future,
sync_fut: Optional[asyncio.Future],
notify_key: str
) -> None:
await sync_fut
if sync_fut is not None:
logging.debug(f"Syncing notification: {notify_key}")
await sync_fut
self.file_manager.cancel_notification(notify_key)
await asyncio.sleep(.005)
self.server.send_event("file_manager:filelist_changed", result)