Skip to content

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

Fix concurrency issue when writing sha segments

Chocobozzz6e0ff6c5b9f9
diff --git a/server/core/lib/live/live-segment-sha-store.ts b/server/core/lib/live/live-segment-sha-store.ts
index 24aae9f163..3f899f7e49 100644
--- a/server/core/lib/live/live-segment-sha-store.ts
+++ b/server/core/lib/live/live-segment-sha-store.ts
@@ -1,10 +1,11 @@
+import { buildSUUID } from '@peertube/peertube-node-utils'
import { mapToJSON } from '@server/helpers/core-utils.js'
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { MStreamingPlaylistVideo } from '@server/types/models/index.js'
import { writeJson } from 'fs-extra/esm'
import { rename } from 'fs/promises'
import PQueue from 'p-queue'
-import { basename } from 'path'
+import { basename, dirname, join } from 'path'
import { buildSha256Segment } from '../hls.js'
import { storeHLSFileFromPath } from '../object-storage/index.js'
@@ -31,12 +32,17 @@ class LiveSegmentShaStore {
this.videoUUID = options.videoUUID
this.sha256Path = options.sha256Path
- this.sha256PathTMP = options.sha256Path + '.tmp'
+ this.sha256PathTMP = join(dirname(options.sha256Path), buildSUUID() + '-segments-sha256.json.tmp')
this.streamingPlaylist = options.streamingPlaylist
this.sendToObjectStorage = options.sendToObjectStorage
}
+ abort () {
+ this.writeQueue.pause()
+ this.writeQueue.clear()
+ }
+
async addSegmentSha (segmentPath: string) {
logger.debug('Adding live sha segment %s.', segmentPath, lTags(this.videoUUID))
diff --git a/server/core/lib/live/shared/muxing-session.ts b/server/core/lib/live/shared/muxing-session.ts
index 8a5be65c67..161e2fd602 100644
--- a/server/core/lib/live/shared/muxing-session.ts
+++ b/server/core/lib/live/shared/muxing-session.ts
@@ -202,6 +202,8 @@ class MuxingSession extends EventEmitter implements MuxingSession {
this.aborted = true
this.transcodingWrapper.abort()
+
+ if (this.liveSegmentShaStore) this.liveSegmentShaStore.abort()
}
destroy () {