diff options
author | Louis Chemineau <louis@chmn.me> | 2025-03-25 12:38:42 +0100 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2025-03-25 12:38:42 +0100 |
commit | 187a3d26d49574afd1ad059eb005b998987f936b (patch) | |
tree | dc0adf44ba0b116cfbfca0ce77197f693566b11a | |
parent | f85154f1e1a3bfcf022cd1833a3028ea9c63380e (diff) | |
download | nextcloud-server-artonge/optim/close_connection_before_s3_upload.tar.gz nextcloud-server-artonge/optim/close_connection_before_s3_upload.zip |
fix(s3): DRAFT Close connection before writing to bucketartonge/optim/close_connection_before_s3_upload
Writes can be long operations. This commit prevents the accumulation of opened connections.
Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r-- | lib/private/Files/ObjectStore/S3ObjectTrait.php | 16 |
1 files changed, 15 insertions, 1 deletions
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 { |