Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/s3-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.758.0",
"@shopify/semaphore": "^3.1.0",
"@tus/utils": "^0.7.0",
"async-mutex": "^0.5.0",
"debug": "^4.3.4",
"multistream": "^4.1.0"
},
Expand Down
17 changes: 7 additions & 10 deletions packages/s3-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
MemoryKvStore,
} from '@tus/utils'

import {Semaphore, type Permit} from '@shopify/semaphore'
import {Semaphore} from 'async-mutex'
import MultiStream from 'multistream'
import crypto from 'node:crypto'
import path from 'node:path'
Expand Down Expand Up @@ -369,22 +369,23 @@ export class S3Store extends DataStore {
const promises: Promise<void>[] = []
let pendingChunkFilepath: string | null = null
let bytesUploaded = 0
let permit: Permit | undefined
let releasePermit: (() => void) | undefined

const splitterStream = new StreamSplitter({
chunkSize: this.calcOptimalPartSize(size),
directory: os.tmpdir(),
})
.on('beforeChunkStarted', async () => {
permit = await this.partUploadSemaphore.acquire()
const [, release] = await this.partUploadSemaphore.acquire()
releasePermit = release
})
.on('chunkStarted', (filepath) => {
pendingChunkFilepath = filepath
})
.on('chunkFinished', ({path, size: partSize}) => {
pendingChunkFilepath = null

const acquiredPermit = permit
const acquiredRelease = releasePermit
const partNumber = currentPartNumber++

offset += partSize
Expand Down Expand Up @@ -415,9 +416,7 @@ export class S3Store extends DataStore {
fsProm.rm(path).catch(() => {
/* ignore */
})
acquiredPermit?.release().catch(() => {
/* ignore */
})
acquiredRelease?.()
}
})

Expand All @@ -430,9 +429,7 @@ export class S3Store extends DataStore {
promises.push(deferred)
})
.on('chunkError', () => {
permit?.release().catch(() => {
/* ignore */
})
releasePermit?.()
})

try {
Expand Down