fix(s3): DRAFT Close connection before writing to bucket

Writes can be long operations. This commit prevents the accumulation of opened connections.

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2025-03-25 12:38:42 +01:00
parent f85154f1e1
commit 187a3d26d4
No known key found for this signature in database

View file

@ -13,6 +13,7 @@ use Aws\S3\S3Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Utils;
use OC\Files\Stream\SeekableHttpStream;
use OCP\IDBConnection;
use Psr\Http\Message\StreamInterface;
trait S3ObjectTrait {
@ -152,7 +153,14 @@ trait S3ObjectTrait {
$buffer = new Psr7\Stream(fopen('php://temp', 'rw+'));
Utils::copyToStream($psrStream, $buffer, $this->putSizeLimit);
$buffer->seek(0);
if ($buffer->getSize() < $this->putSizeLimit) {
$size = $buffer->getSize();
if ($size > 200000000) {
/** @var IDBConnection $connection */
$connection = \OCP\Server::get(IDBConnection::class);
$connection->close();
}
if ($size < $this->putSizeLimit) {
// buffer is fully seekable, so use it directly for the small upload
$this->writeSingle($urn, $buffer, $mimetype);
} else {
@ -160,6 +168,12 @@ trait S3ObjectTrait {
$this->writeMultiPart($urn, $loadStream, $mimetype);
}
} else {
if ($size > 200000000) {
/** @var IDBConnection $connection */
$connection = \OCP\Server::get(IDBConnection::class);
$connection->close();
}
if ($size < $this->putSizeLimit) {
$this->writeSingle($urn, $psrStream, $mimetype);
} else {