Skip to content

PHPLIB-1313 Ensure the GridFS stream is saved when the script ends #1197

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

Merged
merged 2 commits into from
Nov 23, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 22, 2023

Fix PHPLIB-1313

By forcing the writable stream to be properly closed, we ensure the file is sent to the server when the process stops.

/* This destructor is a workaround for PHP trying to use the stream well
* after all objects have been destructed. This can cause autoloading
* issues and possibly segmentation faults during PHP shutdown. */
$this->stream = null;
Copy link
Member Author

@GromNaN GromNaN Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove this line introduced by PHPLIB-345 because even if PHP tries to close the stream again, this is no-op.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the new test reproduces also the issue described in PHPLIB-345.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to go back and check, but PHP may also have fixed this issue by shutting down streams earlier in the shutdown process. Either way, manually closing the stream definitely fixes the write issue, but if we want to be absolutely sure we can also reset the stream property as was done previously to ensure the issue does not re-appear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the "autoloading" issue by removing the __destruct() function. So I don't see what would have changed in PHP core for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Since you've confirmed that the current code works around the issue, no objections to merging this as is 👍

@GromNaN GromNaN requested a review from alcaeus November 22, 2023 16:59
@GromNaN
Copy link
Member Author

GromNaN commented Nov 23, 2023

testDanglingOpenWritableStream is failing because now it executes a MongoDB command and the server URI is not read from the config. I updated the test instead of creating a new one.

[2023/11/23 14:49:49.753] FAILURE:  (PHPUnit\Framework\ExpectationFailedException)
[2023/11/23 14:49:49.753] MongoDB\Tests\GridFS\BucketFunctionalTest::testDanglingOpenWritableStream
[2023/11/23 14:49:49.753] Failed asserting that 255 is identical to 0.
[2023/11/23 14:49:49.753] /data/mci/06e79c8f4d646cf1e20e31e5d62575cb/src/tests/GridFS/BucketFunctionalTest.php:867

@GromNaN GromNaN merged commit ad8e187 into mongodb:master Nov 23, 2023
@GromNaN GromNaN deleted the PHPLIB-1313 branch November 23, 2023 15:02
alcaeus added a commit to alcaeus/mongo-php-library that referenced this pull request Jan 15, 2024
* master:
  PHPLIB-1323 Implement `unlink` for GridFS stream wrapper (mongodb#1206)
  PHPLIB-1330: Sync tests for failCommand errorLabels reqs (mongodb#1214)
  PHPLIB-1246: Test PHP 8.3 on Evergreen (mongodb#1213)
  PHPLIB-1324 Implement `rename` for GridFS stream wrapper  (mongodb#1207)
  PHPLIB-1248 Add examples on GridFS (mongodb#1196)
  Deprecate setting GridFS disableMD5 to false explicitly (mongodb#1205)
  PHPLIB-1326: Use more permissive top-level runOnRequirements (mongodb#1210)
  PHPLIB-1206 Add bucket alises for context resolver using GridFS StreamWrapper (mongodb#1138)
  Bump actions/upload-artifact from 3 to 4 (mongodb#1208)
  PHPLIB-1275: Replace apiargs usage in docs with extracts (mongodb#1203)
  Fix title formatting in Client::removeSubscriber() docs (mongodb#1204)
  PHPLIB-1304: Pull mongohouse image from ECR repo (mongodb#1202)
  Fix evergreen failures (mongodb#1200)
  Enable workflows to run for GitHub Merge Queue (mongodb#1199)
  PHPLIB-1313 Ensure the GridFS stream is saved when the script ends (mongodb#1197)
  PHPLIB-1309 Add addSubscriber/removeSubscriber to Client class to ease configuration (mongodb#1195)
  Master is now 1.18-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants