From 460f0ed59f7e3c475878f1cc25f8160937f04987 Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Mon, 26 Apr 2021 19:46:09 +0000 Subject: [PATCH] Bug 1676803 - [remote] Hardening discards of registered FileIO streams. r=remote-protocol-reviewers,jdescottes In some situations the FileIO stream's underlying file might not exist anymore. Discarding the stream should not fail. Depends on D112004 Differential Revision: https://phabricator.services.mozilla.com/D113379 --- remote/cdp/StreamRegistry.jsm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/remote/cdp/StreamRegistry.jsm b/remote/cdp/StreamRegistry.jsm index f35ccacdffc4..8780c01c7f06 100644 --- a/remote/cdp/StreamRegistry.jsm +++ b/remote/cdp/StreamRegistry.jsm @@ -47,14 +47,16 @@ class StreamRegistry { async _discard(stream) { if (stream instanceof OS.File) { - const fileInfo = await stream.stat(); - stream.close(); + let fileInfo; // Also remove the temporary file try { + fileInfo = await stream.stat(); + + stream.close(); await OS.File.remove(fileInfo.path, { ignoreAbsent: true }); } catch (e) { - console.error(`Failed to remove ${fileInfo.path}: ${e.message}`); + console.error(`Failed to remove ${fileInfo?.path}: ${e.message}`); } } }