From 187a3d26d49574afd1ad059eb005b998987f936b Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 25 Mar 2025 12:38:42 +0100 Subject: [PATCH] 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 --- lib/private/Files/ObjectStore/S3ObjectTrait.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 9d7cfa644e6..1329f1712e3 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -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 {