Skip to content

Commit

Permalink
Patch gostream release bug for modules (viamrobotics#4330)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexbabe authored Aug 30, 2024
1 parent 680ca14 commit 7934630
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gostream/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ func (pc *producerConsumer[T, U]) stop() {
pc.consumerCond.L.Unlock()
pc.activeBackgroundWorkers.Wait()

pc.currentMu.Lock()
defer pc.currentMu.Unlock()
pc.current = nil

// reset
cancelCtx, cancel := context.WithCancel(WithMIMETypeHint(pc.rootCancelCtx, pc.mimeType))
pc.cancelCtxMu.Lock()
Expand Down
22 changes: 22 additions & 0 deletions gostream/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,25 @@ func TestStreamMultipleConsumers(t *testing.T) {
test.That(t, wrappedImg.released.Load(), test.ShouldBeTrue)
}
}

func TestStreamWithoutNext(t *testing.T) {
colors := []*WrappedImage{createWrappedImage(t, rimage.Red)}

imgSource := &imageSource{WrappedImages: colors}
videoSrc := NewVideoSource(imgSource, prop.Video{})

// Start stream
stream, err := videoSrc.Stream(context.Background())
test.That(t, err, test.ShouldBeNil)
// Get one frame
_, release, err := stream.Next(context.Background())
test.That(t, err, test.ShouldBeNil)
release()
// Close stream
stream.Close(context.Background())

// Spin up stream and close without calling Next
stream, err = videoSrc.Stream(context.Background())
test.That(t, err, test.ShouldBeNil)
stream.Close(context.Background())
}

0 comments on commit 7934630

Please sign in to comment.