Bug 232067

Summary: FileSystemSyncAccessHandle should close platform file handle on close()
Product: WebKit Reporter: Sihui Liu <sihui_liu>
Component: New BugsAssignee: Sihui Liu <sihui_liu>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, ggaren, jonlee, sihui_liu, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 231706    
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Sihui Liu 2021-10-21 01:05:28 PDT
...
Comment 1 Sihui Liu 2021-10-21 01:08:48 PDT
Created attachment 441994 [details]
Patch
Comment 2 Sihui Liu 2021-10-21 08:27:17 PDT
Created attachment 442028 [details]
Patch
Comment 3 youenn fablet 2021-10-21 09:17:52 PDT
Comment on attachment 442028 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=442028&action=review

> Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:53
>          m_source->close(m_identifier, [](auto) { });

We should probably also make sure we close also if ScriptExecutionContext is stopped. Normally there should be no issue but it does not hurt to close sooner rather than later.

> Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:100
> +    if (m_state == State::Closing)

Why do we need the Closing state?
It seems only useful for the promise rejection message.
I am not sure this is worth the effort.

> Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:130
> +        return Exception { InvalidStateError, "AccessHandle is being closed or closed"_s };

I would write it as "AccessHandle is closing or closed" or "AccessHandle is not active".

> LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-close.https.tentative.worker-expected.txt:4
> +FAIL SyncAccessHandle.read fails after SyncAccessHandle.close settles promise_test: Unhandled rejection with value: object "InvalidStateError: AccessHandle is closed"

Why are we failing those tests? Are we missing something to be able to run properly sync_access_handle_test.
It would seem worthwhile to make sure we run these tests properly.
Comment 4 Sihui Liu 2021-10-21 09:32:34 PDT
(In reply to youenn fablet from comment #3)
> Comment on attachment 442028 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=442028&action=review
> 
> > Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:53
> >          m_source->close(m_identifier, [](auto) { });
> 
> We should probably also make sure we close also if ScriptExecutionContext is
> stopped. Normally there should be no issue but it does not hurt to close
> sooner rather than later.

Yeah I will follow up in a separate bugs, filed https://bugs.webkit.org/show_bug.cgi?id=231250 before. 

> 
> > Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:100
> > +    if (m_state == State::Closing)
> 
> Why do we need the Closing state?
> It seems only useful for the promise rejection message.
> I am not sure this is worth the effort.

Will remove.

> 
> > Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:130
> > +        return Exception { InvalidStateError, "AccessHandle is being closed or closed"_s };
> 
> I would write it as "AccessHandle is closing or closed" or "AccessHandle is
> not active".

Sure.

> 
> > LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-close.https.tentative.worker-expected.txt:4
> > +FAIL SyncAccessHandle.read fails after SyncAccessHandle.close settles promise_test: Unhandled rejection with value: object "InvalidStateError: AccessHandle is closed"
> 
> Why are we failing those tests? Are we missing something to be able to run
> properly sync_access_handle_test.
> It would seem worthwhile to make sure we run these tests properly.

I don't think we are missing things for this test. I will adjust the implementation to match the test expectation.
Comment 5 Radar WebKit Bug Importer 2021-10-21 11:47:41 PDT
<rdar://problem/84517013>
Comment 6 Sihui Liu 2021-10-21 12:00:54 PDT
Created attachment 442055 [details]
Patch
Comment 7 EWS 2021-10-21 16:13:10 PDT
Committed r284652 (243372@main): <https://commits.webkit.org/243372@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 442055 [details].