Skip to content

Breaking change in 3.383.1: file handles are now closed by S3Client->upload() #3295

Description

@davidsev

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

  • Select this option if this issue appears to be a regression.

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

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.investigatingThis issue is being investigated and/or work is in progress to resolve the issue.potential-regressionMarking this issue as a potential regression to be checked by team member

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions