Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Prevent concurrency issues on small system

Chocobozzz630f0599a806
diff --git a/server/core/helpers/database-utils.ts b/server/core/helpers/database-utils.ts
index 28fd20246b..87edf05ee0 100644
--- a/server/core/helpers/database-utils.ts
+++ b/server/core/helpers/database-utils.ts
@@ -68,11 +68,14 @@ export function transactionRetryer<T> (func: (err: any, data: T) => any) {
})
}
-export function saveInTransactionWithRetries<T extends Pick<Model, 'save' | 'changed'>> (model: T) {
+export function saveInTransactionWithRetries<T extends Pick<Model, 'save' | 'changed'>> (
+ model: T,
+ isolationLevel: Transaction.ISOLATION_LEVELS = Transaction.ISOLATION_LEVELS.SERIALIZABLE
+) {
const changedKeys = model.changed() || []
return retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async transaction => {
+ return sequelizeTypescript.transaction({ isolationLevel }, async transaction => {
try {
await model.save({ transaction })
} catch (err) {
diff --git a/server/core/lib/runners/job-handlers/abstract-job-handler.ts b/server/core/lib/runners/job-handlers/abstract-job-handler.ts
index a5e1457e2a..b1e8793ec7 100644
--- a/server/core/lib/runners/job-handlers/abstract-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/abstract-job-handler.ts
@@ -28,6 +28,7 @@ import { PeerTubeSocket } from '@server/lib/peertube-socket.js'
import { RunnerJobModel } from '@server/models/runner/runner-job.js'
import { setAsUpdated } from '@server/models/shared/update.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
+import { Transaction } from 'sequelize'
type CreateRunnerJobArg =
| {
@@ -98,7 +99,7 @@ export abstract class AbstractJobHandler<C, U extends RunnerJobUpdatePayload, S
priority
})
- await saveInTransactionWithRetries(runnerJob)
+ await saveInTransactionWithRetries(runnerJob, Transaction.ISOLATION_LEVELS.READ_COMMITTED)
if (runnerJob.state === RunnerJobState.PENDING) {
PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()