<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[284815] branches/safari-612-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/284815">284815</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2021-10-25 12:10:30 -0700 (Mon, 25 Oct 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/284692">r284692</a>. rdar://problem/84553142

    Followup to <a href="http://trac.webkit.org/projects/webkit/changeset/284652">r284652</a>: 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</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari612branchLayoutTestsChangeLog">branches/safari-612-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari612branchLayoutTestsstoragefilesystemaccessresourcessyncaccesshandleclosejs">branches/safari-612-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js</a></li>
<li><a href="#branchessafari612branchLayoutTestsstoragefilesystemaccesssyncaccesshandlecloseworkerexpectedtxt">branches/safari-612-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt</a></li>
<li><a href="#branchessafari612branchSourceWebCoreChangeLog">branches/safari-612-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandlecpp">branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandleh">branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h</a></li>
<li><a href="#branchessafari612branchSourceWebKitChangeLog">branches/safari-612-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceWebKitNetworkProcessstorageFileSystemStorageHandlecpp">branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp</a></li>
<li><a href="#branchessafari612branchSourceWebKitNetworkProcessstorageFileSystemStorageHandleh">branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h</a></li>
<li><a href="#branchessafari612branchSourceWebKitPlatformIPCcocoaSharedFileHandleCocoacpp">branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari612branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/LayoutTests/ChangeLog (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/LayoutTests/ChangeLog 2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/LayoutTests/ChangeLog    2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -1,5 +1,63 @@
</span><span class="cx"> 2021-10-25  Null  <null@apple.com>
</span><span class="cx"> 
</span><ins>+        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_liu@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-25  Null  <null@apple.com>
+
</ins><span class="cx">         Cherry-pick r284652. rdar://problem/84517013
</span><span class="cx"> 
</span><span class="cx">     FileSystemSyncAccessHandle should close platform file handle on close()
</span></span></pre></div>
<a id="branchessafari612branchLayoutTestsstoragefilesystemaccessresourcessyncaccesshandleclosejs"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js    2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-close.js       2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -4,7 +4,15 @@
</span><span class="cx"> 
</span><span class="cx"> description("This test checks close() of FileSystemSyncAccessHandle");
</span><span class="cx"> 
</span><del>-var accessHandle, promise;
</del><ins>+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 },
+];
</ins><span class="cx"> 
</span><span class="cx"> function finishTest(error)
</span><span class="cx"> {
</span><span class="lines">@@ -14,31 +22,75 @@
</span><span class="cx">     finishJSTest();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-async function testFunctions()
</del><ins>+function testSyncFunction(currentFunction)
</ins><span class="cx"> {
</span><del>-    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 })");
</del><ins>+    try {
+        var result = accessHandle[currentFunction.name].apply(accessHandle, currentFunction.args);
+        return null;
+    } catch (err) {
+        return err;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-async function test() {
</del><ins>+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() 
+{
</ins><span class="cx">     try {
</span><span class="cx">         var rootHandle = await navigator.storage.getDirectory();
</span><span class="cx">         // Create a new file for this test.
</span><span class="cx">         await rootHandle.removeEntry("sync-access-handle-close.txt").then(() => { }, () => { });
</span><del>-        var fileHandle = await rootHandle.getFileHandle("sync-access-handle-close.txt", { "create" : true  });
</del><ins>+        fileHandle = await rootHandle.getFileHandle("sync-access-handle-close.txt", { "create" : true  });
</ins><span class="cx">         accessHandle = await fileHandle.createSyncAccessHandle();
</span><span class="cx"> 
</span><span class="cx">         var closePromise = accessHandle.close();
</span><span class="cx">         debug("test after invoking close():");
</span><del>-        testFunctions();
</del><ins>+        await testFunctions();
</ins><span class="cx"> 
</span><span class="cx">         debug("test after close() is done:");
</span><span class="cx">         await closePromise;
</span><del>-        testFunctions();
</del><ins>+        await testFunctions();
</ins><span class="cx"> 
</span><ins>+        debug("test closing multiple handles:");
+        await testMultipleHandles();
+
</ins><span class="cx">         finishTest();
</span><span class="cx">     } catch (error) {
</span><span class="cx">         finishTest(error);
</span></span></pre></div>
<a id="branchessafari612branchLayoutTestsstoragefilesystemaccesssyncaccesshandlecloseworkerexpectedtxt"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt     2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/LayoutTests/storage/filesystemaccess/sync-access-handle-close-worker-expected.txt        2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -5,17 +5,25 @@
</span><span class="cx"> 
</span><span class="cx"> Starting worker: resources/sync-access-handle-close.js
</span><span class="cx"> [Worker] test after invoking close():
</span><del>-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'.
</del><ins>+[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"
</ins><span class="cx"> [Worker] test after close() is done:
</span><del>-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'.
</del><ins>+[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
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/ChangeLog      2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -1,5 +1,64 @@
</span><span class="cx"> 2021-10-25  Null  <null@apple.com>
</span><span class="cx"> 
</span><ins>+        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_liu@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-25  Null  <null@apple.com>
+
</ins><span class="cx">         Cherry-pick r284652. rdar://problem/84517013
</span><span class="cx"> 
</span><span class="cx">     FileSystemSyncAccessHandle should close platform file handle on close()
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandlecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp        2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp   2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_closePromises.isEmpty());
</span><del>-    m_source->close(m_identifier, [](auto) { });
</del><ins>+    closeInternal([](auto) { });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool FileSystemSyncAccessHandle::isClosingOrClosed() const
</span><span class="lines">@@ -60,6 +60,12 @@
</span><span class="cx">     return m_closeResult || !m_closePromises.isEmpty();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void FileSystemSyncAccessHandle::closeInternal(CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
+{
+    FileSystem::closeFile(m_file);
+    m_source->close(m_identifier, WTFMove(completionHandler));
+}
+
</ins><span class="cx"> void FileSystemSyncAccessHandle::truncate(unsigned long long size, DOMPromiseDeferred<void>&& promise)
</span><span class="cx"> {
</span><span class="cx">     if (isClosingOrClosed())
</span><span class="lines">@@ -112,11 +118,8 @@
</span><span class="cx">     if (isClosing)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    FileSystem::closeFile(m_file);
-    m_file = FileSystem::invalidPlatformFileHandle;
-
</del><span class="cx">     m_pendingOperationCount++;
</span><del>-    m_source->close(m_identifier, [this, protectedThis = Ref { *this }](auto result) mutable {
</del><ins>+    closeInternal([this, protectedThis = Ref { *this }](auto result) mutable {
</ins><span class="cx">         m_pendingOperationCount--;
</span><span class="cx">         didClose(WTFMove(result));
</span><span class="cx">     });
</span></span></pre></div>
<a id="branchessafari612branchSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandleh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h  2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h     2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx"> private:
</span><span class="cx">     FileSystemSyncAccessHandle(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle);
</span><span class="cx">     bool isClosingOrClosed() const;
</span><ins>+    void closeInternal(CompletionHandler<void(ExceptionOr<void>&&)>&&);
</ins><span class="cx"> 
</span><span class="cx">     Ref<FileSystemFileHandle> m_source;
</span><span class="cx">     FileSystemSyncAccessHandleIdentifier m_identifier;
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/ChangeLog       2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog  2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -1,5 +1,63 @@
</span><span class="cx"> 2021-10-25  Null  <null@apple.com>
</span><span class="cx"> 
</span><ins>+        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_liu@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-25  Null  <null@apple.com>
+
</ins><span class="cx">         Cherry-pick r284712. rdar://problem/81586485
</span><span class="cx"> 
</span><span class="cx">     AX: Inform AX when the injected bundle sends a synchronous message
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitNetworkProcessstorageFileSystemStorageHandlecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp      2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp 2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -63,6 +63,12 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+FileSystemStorageHandle::~FileSystemStorageHandle()
+{
+    if (m_handle != FileSystem::invalidPlatformFileHandle)
+        FileSystem::closeFile(m_handle);
+}
+
</ins><span class="cx"> bool FileSystemStorageHandle::isSameEntry(WebCore::FileSystemHandleIdentifier identifier)
</span><span class="cx"> {
</span><span class="cx">     auto path = m_manager->getPath(identifier);
</span><span class="lines">@@ -165,7 +171,6 @@
</span><span class="cx">     auto ipcHandle = IPC::SharedFileHandle::create(m_handle);
</span><span class="cx">     if (!ipcHandle) {
</span><span class="cx">         FileSystem::closeFile(m_handle);
</span><del>-        m_handle = FileSystem::invalidPlatformFileHandle;
</del><span class="cx">         return makeUnexpected(FileSystemStorageError::BackendNotSupported);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -223,16 +228,15 @@
</span><span class="cx"> 
</span><span class="cx"> std::optional<FileSystemStorageError> FileSystemStorageHandle::close(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
</span><span class="cx"> {
</span><del>-    if (!m_manager)
-        return FileSystemStorageError::Unknown;
-
</del><span class="cx">     if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
</span><span class="cx">         return FileSystemStorageError::Unknown;
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_handle != FileSystem::invalidPlatformFileHandle);
</span><span class="cx">     FileSystem::closeFile(m_handle);
</span><del>-    m_handle = FileSystem::invalidPlatformFileHandle;
</del><span class="cx"> 
</span><ins>+    if (!m_manager)
+        return FileSystemStorageError::Unknown;
+
</ins><span class="cx">     m_manager->releaseLockForFile(m_path, m_identifier);
</span><span class="cx">     m_activeSyncAccessHandle = std::nullopt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitNetworkProcessstorageFileSystemStorageHandleh"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h        2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h   2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> public:
</span><span class="cx">     enum class Type : uint8_t { File, Directory, Any };
</span><span class="cx">     FileSystemStorageHandle(FileSystemStorageManager&, Type, String&& path, String&& name);
</span><ins>+    ~FileSystemStorageHandle();
</ins><span class="cx"> 
</span><span class="cx">     WebCore::FileSystemHandleIdentifier identifier() const { return m_identifier; }
</span><span class="cx">     const String& path() const { return m_path; }
</span></span></pre></div>
<a id="branchessafari612branchSourceWebKitPlatformIPCcocoaSharedFileHandleCocoacpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp (284814 => 284815)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp    2021-10-25 19:10:23 UTC (rev 284814)
+++ branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp       2021-10-25 19:10:30 UTC (rev 284815)
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx">     if (fd == -1)
</span><span class="cx">         return SharedFileHandle { };
</span><span class="cx"> 
</span><del>-    return SharedFileHandle::create(fileport_makefd(machPort.port()));
</del><ins>+    return SharedFileHandle::create(fd);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace IPC
</span></span></pre>
</div>
</div>

</body>
</html>