Skip to content

Commit

Permalink
fix: tus locker release (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos authored Oct 17, 2024
1 parent 689d255 commit 729bbdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/internal/monitoring/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { TenantConnection } from '@internal/database'
import { S3Store } from '@tus/s3-store'
import { Upload } from '@aws-sdk/lib-storage'
import { StreamSplitter } from '@tus/server'
import { PgLock } from '@storage/protocols/tus'

const tracingEnabled = process.env.TRACING_ENABLED === 'true'
const headersEnv = process.env.OTEL_EXPORTER_OTLP_TRACES_HEADERS || ''
Expand Down Expand Up @@ -259,6 +260,11 @@ const sdk = new NodeSDK({
},
},
}),
new ClassInstrumentation({
targetClass: PgLock,
enabled: true,
methodsToInstrument: ['lock', 'unlock', 'acquireLock'],
}),
new ClassInstrumentation({
targetClass: S3Client,
enabled: true,
Expand Down
10 changes: 5 additions & 5 deletions src/storage/protocols/tus/postgres-locker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Lock, Locker, RequestRelease } from '@tus/server'
import { clearTimeout } from 'timers'
import EventEmitter from 'events'
import { Database, DBError } from '../../database'
import { clearTimeout } from 'node:timers'
import EventEmitter from 'node:events'
import { Database } from '../../database'
import { PubSubAdapter } from '@internal/pubsub'
import { UploadId } from './upload-id'
import { ERRORS } from '@internal/errors'
import { ErrorCode, ERRORS, StorageBackendError } from '@internal/errors'

const REQUEST_LOCK_RELEASE_MESSAGE = 'REQUEST_LOCK_RELEASE'

Expand Down Expand Up @@ -94,7 +94,7 @@ export class PgLock implements Lock {
await db.mustLockObject(uploadId.bucket, uploadId.objectName, uploadId.version)
return true
} catch (e) {
if (e instanceof DBError && e.message === 'resource_locked') {
if (e instanceof StorageBackendError && e.code === ErrorCode.ResourceLocked) {
await this.notifier.release(id)
await new Promise((resolve) => {
setTimeout(resolve, 500)
Expand Down

0 comments on commit 729bbdf

Please sign in to comment.