Diff
Modified: branches/safari-612.3.2.1-branch/LayoutTests/ChangeLog (284733 => 284734)
--- branches/safari-612.3.2.1-branch/LayoutTests/ChangeLog 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/LayoutTests/ChangeLog 2021-10-23 01:22:54 UTC (rev 284734)
@@ -1,5 +1,63 @@
2021-10-22 Russell Epstein <repst...@apple.com>
+ Cherry-pick r284692. rdar://problem/84553142
+
+ Followup to r284652: ensure file handle is closed in web process
+ https://bugs.webkit.org/show_bug.cgi?id=232127
+
+ Reviewed by Youenn Fablet.
+
+ Source/WebCore:
+
+ Covered by test: storage/filesystemaccess/sync-access-handle-close-worker.html
+
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
+ (WebCore::FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle): make sure file handle is closed when
+ FileSystemSyncAccessHandle is destroyed.
+ (WebCore::FileSystemSyncAccessHandle::closeInternal):
+ (WebCore::FileSystemSyncAccessHandle::close):
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
+
+ Source/WebKit:
+
+ * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+ (WebKit::FileSystemStorageHandle::~FileSystemStorageHandle):
+ (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
+ (WebKit::FileSystemStorageHandle::close):
+ * NetworkProcess/storage/FileSystemStorageHandle.h:
+ * Platform/IPC/cocoa/SharedFileHandleCocoa.cpp: an extra fd is created here and does not get closed.
+ (IPC::SharedFileHandle::decode):
+
+ LayoutTests:
+
+ * storage/filesystemaccess/resources/sync-access-handle-close.js:
+ (testSyncFunction):
+ (async testAsyncFunction):
+ (async testFunctions):
+ (async testMultipleHandles):
+ (async test):
+ * storage/filesystemaccess/sync-access-handle-close-worker-expected.txt:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-10-22 Sihui Liu <sihui_...@apple.com>
+
+ Followup to r284652: ensure file handle is closed in web process
+ https://bugs.webkit.org/show_bug.cgi?id=232127
+
+ Reviewed by Youenn Fablet.
+
+ * storage/filesystemaccess/resources/sync-access-handle-close.js:
+ (testSyncFunction):
+ (async testAsyncFunction):
+ (async testFunctions):
+ (async testMultipleHandles):
+ (async test):
+ * storage/filesystemaccess/sync-access-handle-close-worker-expected.txt:
+
+2021-10-22 Russell Epstein <repst...@apple.com>
+
Cherry-pick r284652. rdar://problem/84517013
FileSystemSyncAccessHandle should close platform file handle on close()
Modified: branches/safari-612.3.2.1-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js (284733 => 284734)
--- branches/safari-612.3.2.1-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js 2021-10-23 01:22:54 UTC (rev 284734)
@@ -4,7 +4,15 @@
description("This test checks close() of FileSystemSyncAccessHandle");
-var accessHandle, promise;
+var accessHandle, fileHandle, error;
+const buffer = new ArrayBuffer(1);
+const options = { "at" : 0 };
+var functions = [
+ { name : "getSize" },
+ { name : "flush" },
+ { name : "read", args : [buffer, options], sync : true },
+ { name : "write", args : [buffer, options], sync : true },
+];
function finishTest(error)
{
@@ -14,31 +22,75 @@
finishJSTest();
}
-async function testFunctions()
+function testSyncFunction(currentFunction)
{
- shouldThrow("await accessHandle.close()");
- shouldThrow("await accessHandle.getSize()");
- shouldThrow("await accessHandle.flush()");
- shouldThrow("await accessHandle.read(new ArrayBuffer(1), { \"at\" : 0 })");
- shouldThrow("await accessHandle.write(new ArrayBuffer(1), { \"at\" : 0 })");
+ try {
+ var result = accessHandle[currentFunction.name].apply(accessHandle, currentFunction.args);
+ return null;
+ } catch (err) {
+ return err;
+ }
}
-async function test() {
+async function testAsyncFunction(func)
+{
+ var promise = accessHandle[func.name].apply(accessHandle, func.args);
+ return promise.then((value) => {
+ return func.name + " function should throw exception but didn't";
+ }, (err) => {
+ return err;
+ });
+}
+
+async function testFunctions()
+{
+ for (const func of functions) {
+ debug("testing " + func.name);
+
+ if (func.sync) {
+ error = testSyncFunction(func);
+ } else {
+ error = await testAsyncFunction(func);
+ }
+
+ shouldBeEqualToString("error.toString()", "InvalidStateError: AccessHandle is closing or closed");
+ }
+}
+
+async function testMultipleHandles()
+{
+ // Current limit of file descriptor count is 256.
+ for (let i = 0; i < 512; i++) {
+ try {
+ accessHandle = await fileHandle.createSyncAccessHandle();
+ await accessHandle.close();
+ } catch (err) {
+ throw "Failed at No." + i + " handle: " + err.toString();
+ }
+ }
+ debug("Create and close access handles successfully");
+}
+
+async function test()
+{
try {
var rootHandle = await navigator.storage.getDirectory();
// Create a new file for this test.
await rootHandle.removeEntry("sync-access-handle-close.txt").then(() => { }, () => { });
- var fileHandle = await rootHandle.getFileHandle("sync-access-handle-close.txt", { "create" : true });
+ fileHandle = await rootHandle.getFileHandle("sync-access-handle-close.txt", { "create" : true });
accessHandle = await fileHandle.createSyncAccessHandle();
var closePromise = accessHandle.close();
debug("test after invoking close():");
- testFunctions();
+ await testFunctions();
debug("test after close() is done:");
await closePromise;
- testFunctions();
+ await testFunctions();
+ debug("test closing multiple handles:");
+ await testMultipleHandles();
+
finishTest();
} catch (error) {
finishTest(error);
Modified: branches/safari-612.3.2.1-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt (284733 => 284734)
--- branches/safari-612.3.2.1-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt 2021-10-23 01:22:54 UTC (rev 284734)
@@ -5,17 +5,25 @@
Starting worker: resources/sync-access-handle-close.js
[Worker] test after invoking close():
-PASS [Worker] await accessHandle.close() threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.getSize() threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.flush() threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.read(new ArrayBuffer(1), { "at" : 0 }) threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.write(new ArrayBuffer(1), { "at" : 0 }) threw exception SyntaxError: Unexpected identifier 'accessHandle'.
+[Worker] testing getSize
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] testing flush
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] testing read
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] testing write
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
[Worker] test after close() is done:
-PASS [Worker] await accessHandle.close() threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.getSize() threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.flush() threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.read(new ArrayBuffer(1), { "at" : 0 }) threw exception SyntaxError: Unexpected identifier 'accessHandle'.
-PASS [Worker] await accessHandle.write(new ArrayBuffer(1), { "at" : 0 }) threw exception SyntaxError: Unexpected identifier 'accessHandle'.
+[Worker] testing getSize
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] testing flush
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] testing read
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] testing write
+PASS [Worker] error.toString() is "InvalidStateError: AccessHandle is closing or closed"
+[Worker] test closing multiple handles:
+[Worker] Create and close access handles successfully
PASS successfullyParsed is true
TEST COMPLETE
Modified: branches/safari-612.3.2.1-branch/Source/WebCore/ChangeLog (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebCore/ChangeLog 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebCore/ChangeLog 2021-10-23 01:22:54 UTC (rev 284734)
@@ -1,5 +1,64 @@
2021-10-22 Russell Epstein <repst...@apple.com>
+ Cherry-pick r284692. rdar://problem/84553142
+
+ Followup to r284652: ensure file handle is closed in web process
+ https://bugs.webkit.org/show_bug.cgi?id=232127
+
+ Reviewed by Youenn Fablet.
+
+ Source/WebCore:
+
+ Covered by test: storage/filesystemaccess/sync-access-handle-close-worker.html
+
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
+ (WebCore::FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle): make sure file handle is closed when
+ FileSystemSyncAccessHandle is destroyed.
+ (WebCore::FileSystemSyncAccessHandle::closeInternal):
+ (WebCore::FileSystemSyncAccessHandle::close):
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
+
+ Source/WebKit:
+
+ * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+ (WebKit::FileSystemStorageHandle::~FileSystemStorageHandle):
+ (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
+ (WebKit::FileSystemStorageHandle::close):
+ * NetworkProcess/storage/FileSystemStorageHandle.h:
+ * Platform/IPC/cocoa/SharedFileHandleCocoa.cpp: an extra fd is created here and does not get closed.
+ (IPC::SharedFileHandle::decode):
+
+ LayoutTests:
+
+ * storage/filesystemaccess/resources/sync-access-handle-close.js:
+ (testSyncFunction):
+ (async testAsyncFunction):
+ (async testFunctions):
+ (async testMultipleHandles):
+ (async test):
+ * storage/filesystemaccess/sync-access-handle-close-worker-expected.txt:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-10-22 Sihui Liu <sihui_...@apple.com>
+
+ Followup to r284652: ensure file handle is closed in web process
+ https://bugs.webkit.org/show_bug.cgi?id=232127
+
+ Reviewed by Youenn Fablet.
+
+ Covered by test: storage/filesystemaccess/sync-access-handle-close-worker.html
+
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
+ (WebCore::FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle): make sure file handle is closed when
+ FileSystemSyncAccessHandle is destroyed.
+ (WebCore::FileSystemSyncAccessHandle::closeInternal):
+ (WebCore::FileSystemSyncAccessHandle::close):
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
+
+2021-10-22 Russell Epstein <repst...@apple.com>
+
Cherry-pick r284652. rdar://problem/84517013
FileSystemSyncAccessHandle should close platform file handle on close()
Modified: branches/safari-612.3.2.1-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp 2021-10-23 01:22:54 UTC (rev 284734)
@@ -52,7 +52,7 @@
return;
ASSERT(m_closePromises.isEmpty());
- m_source->close(m_identifier, [](auto) { });
+ closeInternal([](auto) { });
}
bool FileSystemSyncAccessHandle::isClosingOrClosed() const
@@ -60,6 +60,12 @@
return m_closeResult || !m_closePromises.isEmpty();
}
+void FileSystemSyncAccessHandle::closeInternal(CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
+{
+ FileSystem::closeFile(m_file);
+ m_source->close(m_identifier, WTFMove(completionHandler));
+}
+
void FileSystemSyncAccessHandle::truncate(unsigned long long size, DOMPromiseDeferred<void>&& promise)
{
if (isClosingOrClosed())
@@ -112,11 +118,8 @@
if (isClosing)
return;
- FileSystem::closeFile(m_file);
- m_file = FileSystem::invalidPlatformFileHandle;
-
m_pendingOperationCount++;
- m_source->close(m_identifier, [this, protectedThis = Ref { *this }](auto result) mutable {
+ closeInternal([this, protectedThis = Ref { *this }](auto result) mutable {
m_pendingOperationCount--;
didClose(WTFMove(result));
});
Modified: branches/safari-612.3.2.1-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h 2021-10-23 01:22:54 UTC (rev 284734)
@@ -57,6 +57,7 @@
private:
FileSystemSyncAccessHandle(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle);
bool isClosingOrClosed() const;
+ void closeInternal(CompletionHandler<void(ExceptionOr<void>&&)>&&);
Ref<FileSystemFileHandle> m_source;
FileSystemSyncAccessHandleIdentifier m_identifier;
Modified: branches/safari-612.3.2.1-branch/Source/WebKit/ChangeLog (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebKit/ChangeLog 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebKit/ChangeLog 2021-10-23 01:22:54 UTC (rev 284734)
@@ -1,3 +1,61 @@
+2021-10-22 Russell Epstein <repst...@apple.com>
+
+ Cherry-pick r284692. rdar://problem/84553142
+
+ Followup to r284652: ensure file handle is closed in web process
+ https://bugs.webkit.org/show_bug.cgi?id=232127
+
+ Reviewed by Youenn Fablet.
+
+ Source/WebCore:
+
+ Covered by test: storage/filesystemaccess/sync-access-handle-close-worker.html
+
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
+ (WebCore::FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle): make sure file handle is closed when
+ FileSystemSyncAccessHandle is destroyed.
+ (WebCore::FileSystemSyncAccessHandle::closeInternal):
+ (WebCore::FileSystemSyncAccessHandle::close):
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
+
+ Source/WebKit:
+
+ * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+ (WebKit::FileSystemStorageHandle::~FileSystemStorageHandle):
+ (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
+ (WebKit::FileSystemStorageHandle::close):
+ * NetworkProcess/storage/FileSystemStorageHandle.h:
+ * Platform/IPC/cocoa/SharedFileHandleCocoa.cpp: an extra fd is created here and does not get closed.
+ (IPC::SharedFileHandle::decode):
+
+ LayoutTests:
+
+ * storage/filesystemaccess/resources/sync-access-handle-close.js:
+ (testSyncFunction):
+ (async testAsyncFunction):
+ (async testFunctions):
+ (async testMultipleHandles):
+ (async test):
+ * storage/filesystemaccess/sync-access-handle-close-worker-expected.txt:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-10-22 Sihui Liu <sihui_...@apple.com>
+
+ Followup to r284652: ensure file handle is closed in web process
+ https://bugs.webkit.org/show_bug.cgi?id=232127
+
+ Reviewed by Youenn Fablet.
+
+ * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+ (WebKit::FileSystemStorageHandle::~FileSystemStorageHandle):
+ (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
+ (WebKit::FileSystemStorageHandle::close):
+ * NetworkProcess/storage/FileSystemStorageHandle.h:
+ * Platform/IPC/cocoa/SharedFileHandleCocoa.cpp: an extra fd is created here and does not get closed.
+ (IPC::SharedFileHandle::decode):
+
2021-10-19 Russell Epstein <repst...@apple.com>
Revert r283931. rdar://problem/83953710
Modified: branches/safari-612.3.2.1-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp 2021-10-23 01:22:54 UTC (rev 284734)
@@ -63,6 +63,12 @@
}
}
+FileSystemStorageHandle::~FileSystemStorageHandle()
+{
+ if (m_handle != FileSystem::invalidPlatformFileHandle)
+ FileSystem::closeFile(m_handle);
+}
+
bool FileSystemStorageHandle::isSameEntry(WebCore::FileSystemHandleIdentifier identifier)
{
auto path = m_manager->getPath(identifier);
@@ -165,7 +171,6 @@
auto ipcHandle = IPC::SharedFileHandle::create(m_handle);
if (!ipcHandle) {
FileSystem::closeFile(m_handle);
- m_handle = FileSystem::invalidPlatformFileHandle;
return makeUnexpected(FileSystemStorageError::BackendNotSupported);
}
@@ -223,16 +228,15 @@
std::optional<FileSystemStorageError> FileSystemStorageHandle::close(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
{
- if (!m_manager)
- return FileSystemStorageError::Unknown;
-
if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
return FileSystemStorageError::Unknown;
ASSERT(m_handle != FileSystem::invalidPlatformFileHandle);
FileSystem::closeFile(m_handle);
- m_handle = FileSystem::invalidPlatformFileHandle;
+ if (!m_manager)
+ return FileSystemStorageError::Unknown;
+
m_manager->releaseLockForFile(m_path, m_identifier);
m_activeSyncAccessHandle = std::nullopt;
Modified: branches/safari-612.3.2.1-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h 2021-10-23 01:22:54 UTC (rev 284734)
@@ -44,6 +44,7 @@
public:
enum class Type : uint8_t { File, Directory, Any };
FileSystemStorageHandle(FileSystemStorageManager&, Type, String&& path, String&& name);
+ ~FileSystemStorageHandle();
WebCore::FileSystemHandleIdentifier identifier() const { return m_identifier; }
const String& path() const { return m_path; }
Modified: branches/safari-612.3.2.1-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp (284733 => 284734)
--- branches/safari-612.3.2.1-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp 2021-10-23 01:22:47 UTC (rev 284733)
+++ branches/safari-612.3.2.1-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp 2021-10-23 01:22:54 UTC (rev 284734)
@@ -57,7 +57,7 @@
if (fd == -1)
return SharedFileHandle { };
- return SharedFileHandle::create(fileport_makefd(machPort.port()));
+ return SharedFileHandle::create(fd);
}
} // namespace IPC