Skip to content

Commit e0da14f

Browse files
milos-lkclaude
andauthored
Raise minimum image upload queue capacity to absorb frame bursts (#1338)
* Raise minimum image upload queue capacity to absorb frame bursts A capture interval of 3600s or more yields a queue capacity of at most one slot, which the startup frame burst (videorate skip-to-first plus the first rate-aligned frame) overflows while the first upload is in flight, failing the egress with 'upload queue full' at startup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Address review: use max builtin, reword test comment Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent d2a6229 commit e0da14f

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

pkg/pipeline/sink/image.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ type imageUpdate struct {
5454
filename string
5555
}
5656

57+
// covers frame bursts that outpace the capture interval: videorate's
58+
// skip-to-first plus the first rate-aligned frame at startup, and the EOS flush
59+
const minPendingUploads = 4
60+
61+
func imageQueueCapacity(maxUploadQueue int, captureInterval uint32) int {
62+
return max((maxUploadQueue*60)/int(captureInterval), minPendingUploads)
63+
}
64+
5765
func newImageSink(
5866
p *gstreamer.Pipeline,
5967
conf *config.PipelineConfig,
@@ -74,10 +82,6 @@ func newImageSink(
7482
return nil, err
7583
}
7684

77-
maxPendingUploads := (conf.MaxUploadQueue * 60) / int(o.CaptureInterval)
78-
if maxPendingUploads < 1 {
79-
maxPendingUploads = 1
80-
}
8185
return &ImageSink{
8286
base: &base{
8387
bin: imageBin,
@@ -88,7 +92,7 @@ func newImageSink(
8892

8993
conf: conf,
9094
callbacks: callbacks,
91-
createdImages: make(chan *imageUpdate, maxPendingUploads),
95+
createdImages: make(chan *imageUpdate, imageQueueCapacity(conf.MaxUploadQueue, o.CaptureInterval)),
9296
}, nil
9397
}
9498

pkg/pipeline/sink/image_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,13 @@ func TestImageSinkCloseDrainsPendingUploads(t *testing.T) {
162162
default:
163163
}
164164
}
165+
166+
// a capture interval of 3600s or more must not yield a queue too small to
167+
// absorb the startup frame burst
168+
func TestImageQueueCapacity(t *testing.T) {
169+
require.Equal(t, 360, imageQueueCapacity(60, 10))
170+
require.Equal(t, 60, imageQueueCapacity(60, 60))
171+
require.Equal(t, minPendingUploads, imageQueueCapacity(60, 3600))
172+
require.Equal(t, minPendingUploads, imageQueueCapacity(60, 7200))
173+
require.Equal(t, minPendingUploads, imageQueueCapacity(0, 10))
174+
}

0 commit comments

Comments
 (0)