Repository navigation
Conversation
… before a destructor's close ParallelFilesystemDriver creates and owns its pool when none is given, and the files it opens didn't keep that pool alive: once the driver was destroyed (for example replaced as the global filesystem driver), the pool was destroyed too, killing the workers holding the files still open. FileWorker now keeps the pool alive while its file is open. ParallelFile::__destruct() checks that its worker runs, then queues the fclose: if the worker exited meanwhile (its pool was shut down or killed, or it died), the queued close threw StatusError (or WorkerException) in the event loop, where nothing could catch it. The worker took the file with it: those exceptions are now ignored there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related problems with
ParallelFilesystemDriver. Together they throwStatusError: The worker has been shut downinto the event loop, failing whatever is running at the time.1. Open files don't keep the driver's pool alive
When no pool is given, the driver creates its own (
new ContextWorkerPool(...)), and the files it opens don't hold a reference to it. Once the driver is destroyed, for example when it's replaced as the global driver withfilesystem($otherDriver), the pool is destroyed too, andContextWorkerPool::__destruct()kills the workers that still hold open files.FileWorkernow keeps the pool alive while its file is open.2.
ParallelFile::__destruct()races with the worker's exitThe destructor checks that the worker runs, then queues the
fclose. If the worker exits in between (its pool is shut down or killed, or it dies),execute()throwsStatusErrororWorkerExceptionfrom the queued callback, where nothing can catch it. The worker took the file with it, so those two exceptions are now ignored there. Other failures still propagate.How we hit it
In MadelineProto,
Magic::start()replaces the global driver. Files opened before that, through amphp/file's default parallel driver, then fail like this. It happened in every run of one of our tests without ext-uv or ext-eio, and it can happen in any application that uses amphp/file before MadelineProto starts.Tests
Two tests in
ParallelFileTest, both failing before this change withStatusError: The worker has been shut down:testOpenFileKeepsTheDriversPoolAlive: the driver is destroyed while a file it opened is still read.testFileDestroyedBeforeItsWorkerShutsDown: a file is destroyed, then its pool is killed before the queued close runs.The rest of the suite passes.
Port of #105 (3.x).
ParallelFileTest::testSimultaneousLockandtestTryLockLoopexceed their time limits on macOS, with and without this change, so they are unrelated to it.