Skip to content

Commit

Permalink
Storage / S3: Make connection settings configurable (directus#24036)
Browse files Browse the repository at this point in the history
* Make connection settings configurable for S3

* Prettier

* Create angry-frogs-beam.md

* Fix linting

* Handle millisecond logic within S3 driver package

* Remove specific S3 configurations from constants

* Fix linting

* Update .changeset/angry-frogs-beam.md

Co-authored-by: ian <licitdev@gmail.com>

* Organize imports

---------

Co-authored-by: ian <licitdev@gmail.com>
  • Loading branch information
joselcvarela and licitdev authored Nov 20, 2024
1 parent e6e2b8c commit 9f9322e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-frogs-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@directus/storage-driver-s3": patch
---

Made S3 connection settings configurable
4 changes: 3 additions & 1 deletion packages/storage-driver-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
"@directus/utils": "workspace:*",
"@shopify/semaphore": "3.1.0",
"@smithy/node-http-handler": "3.2.4",
"@tus/utils": "0.4.0"
"@tus/utils": "0.4.0",
"ms": "2.1.3"
},
"devDependencies": {
"@directus/tsconfig": "workspace:*",
"@ngneat/falso": "7.2.0",
"@types/ms": "0.7.34",
"@vitest/coverage-v8": "2.1.2",
"tsup": "8.3.0",
"typescript": "5.6.3",
Expand Down
13 changes: 9 additions & 4 deletions packages/storage-driver-s3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { isReadableStream } from '@directus/utils/node';
import { Permit, Semaphore } from '@shopify/semaphore';
import { NodeHttpHandler } from '@smithy/node-http-handler';
import { ERRORS, StreamSplitter, TUS_RESUMABLE } from '@tus/utils';
import ms from 'ms';
import fs, { promises as fsProm } from 'node:fs';
import { Agent as HttpAgent } from 'node:http';
import { Agent as HttpsAgent } from 'node:https';
Expand All @@ -50,6 +51,10 @@ export type DriverS3Config = {
tus?: {
chunkSize?: number;
};
connectionTimeout?: number;
socketTimeout?: number;
maxSockets?: number;
keepAlive?: boolean;
};

export class DriverS3 implements TusDriver {
Expand Down Expand Up @@ -79,10 +84,10 @@ export class DriverS3 implements TusDriver {
* often in rapid succession, hitting the maxSockets limit of 50.
* The requestHandler is customized to get around this.
*/
const connectionTimeout = 5000;
const socketTimeout = 120000;
const maxSockets = 500;
const keepAlive = true;
const connectionTimeout = ms(String(this.config.connectionTimeout ?? 5000));
const socketTimeout = ms(String(this.config.socketTimeout ?? 120000));
const maxSockets = this.config.maxSockets ?? 500;
const keepAlive = this.config.keepAlive ?? true;

const s3ClientConfig: S3ClientConfig = {
requestHandler: new NodeHttpHandler({
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f9322e

Please sign in to comment.