Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No explicit file lock release when write() throws an exception #153

Open
saschanaz opened this issue Dec 6, 2023 · 3 comments
Open

No explicit file lock release when write() throws an exception #153

saschanaz opened this issue Dec 6, 2023 · 3 comments

Comments

@saschanaz
Copy link
Member

What is the issue with the File System Standard?

https://fs.spec.whatwg.org/#write-a-chunk throws when getting a non-FileSystemWriteChunkType:

Let input be the result of converting chunk to a FileSystemWriteChunkType. If this throws an exception, then return a promise rejected with that exception.

But the spec does not say whether this exception should release the lock. In fact, the release only happens within:

  1. closeAlgorithm (step 4.2.2.4.1 in https://fs.spec.whatwg.org/#create-a-new-filesystemwritablefilestream)
  2. abortAlgorithm (step 5.1.1 in https://fs.spec.whatwg.org/#create-a-new-filesystemwritablefilestream)
  3. close() method (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-close)

Errors from writeAlgorithm does not release the lock at all per the spec, as returning a rejected promise is not enough, which leads to a permanent lock as there's no GC-triggered lock release either.

The FS spec probably can get some algorithm to return a promise that waits for the lock release and use it for each exception, but that's sad as the implementations should do extra care for every implementation-specific error conditions. Could be nice if the Streams spec had some async hook to handle the error.

cc @jjjalkanen
cc @domenic @MattiasBuelens

@mkruisselbrink
Copy link
Collaborator

Afaict when the writeAlgorithm rejects, WritableStreamDefaultControllerProcessWrite (https://streams.spec.whatwg.org/#writable-stream-default-controller-process-write) calls WritableStreamFinishInFlightWriteWithError which calls WritableStreamDealWithRejection, which calls WritableStreamFinishErroring, which ends up calling the abort algorithm?

@MattiasBuelens
Copy link

This sounds a lot like whatwg/streams#636.

@saschanaz
Copy link
Member Author

Afaict when the writeAlgorithm rejects, WritableStreamDefaultControllerProcessWrite (https://streams.spec.whatwg.org/#writable-stream-default-controller-process-write) calls WritableStreamFinishInFlightWriteWithError which calls WritableStreamDealWithRejection, which calls WritableStreamFinishErroring, which ends up calling the abort algorithm?

Step 8 of FinishErroring returns early when there's no pending abort request, so not always.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants