Describe the bug
Commit 30ebe6f changed the behaviour of S3Client->upload() to now close the user-supplied file handle. Previously in 3.383.0 the handle was left open.
This new behaviour is un-intuitive (I opened it so it's my responsibility to close it) and breaks existing code that correctly calls fclose()
Regression Issue
Expected Behavior
S3Client->upload() should leave the file handle open.
Current Behavior
The user-supplied file handle is closed.
Reproduction Steps
<?php
require_once __DIR__.'/vendor/autoload.php';
$client = new Aws\S3\S3Client(['region' => 'eu-west-2']);
$fp = fopen('php://memory', 'r+');
fwrite($fp, 'Hello!');
fseek($fp, 0);
$client->upload('BUCKET', 'test', $fp);
fclose($fp);
With aws/aws-sdk-php:3.383.0 this works as expected.
With aws/aws-sdk-php:3.383.1 this results in:
PHP Fatal error: Uncaught TypeError: fclose(): Argument #1 ($stream) must be an open stream resource in test.php:10
Possible Solution
ObjectUploader wraps the provided file pointer in a Guzzle Stream, which calls fclose on destruct. Previously there was a memory leak which prevented this, 30ebe6f fixed that issue and indirectly caused this one.
It looks like the best option would be to use FnStream::decorate() to stub out the close method?
Additional Information/Context
No response
SDK version used
3.383.1
Environment details (Version of PHP (php -v)? OS name and version, etc.)
PHP 8.5.6, tested on OSX and Alpine Linux
Describe the bug
Commit 30ebe6f changed the behaviour of S3Client->upload() to now close the user-supplied file handle. Previously in 3.383.0 the handle was left open.
This new behaviour is un-intuitive (I opened it so it's my responsibility to close it) and breaks existing code that correctly calls fclose()
Regression Issue
Expected Behavior
S3Client->upload() should leave the file handle open.
Current Behavior
The user-supplied file handle is closed.
Reproduction Steps
With aws/aws-sdk-php:3.383.0 this works as expected.
With aws/aws-sdk-php:3.383.1 this results in:
PHP Fatal error: Uncaught TypeError: fclose(): Argument #1 ($stream) must be an open stream resource in test.php:10
Possible Solution
ObjectUploader wraps the provided file pointer in a Guzzle Stream, which calls fclose on destruct. Previously there was a memory leak which prevented this, 30ebe6f fixed that issue and indirectly caused this one.
It looks like the best option would be to use FnStream::decorate() to stub out the close method?
Additional Information/Context
No response
SDK version used
3.383.1
Environment details (Version of PHP (
php -v)? OS name and version, etc.)PHP 8.5.6, tested on OSX and Alpine Linux