Skip to content

Close and free the RTMP sink output context even when writing the trailer fails - #134

Merged
varsill merged 8 commits into
masterfrom
rtmp-sink-close-on-trailer-error
Nov 9, 2026
Merged

varsill merged 8 commits into
masterfrom
rtmp-sink-close-on-trailer-error

Conversation

@varsill

@varsill varsill commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR:

  • solves a memory leak by making sure that the avio context is closed and the output
    context is freed even when writing the stream trailer fails (which happens in case of
    "Broken Pipe" errors)
  • makes sure we are not raising in the resource destructor
  • guards every sink NIF against a closed or not yet connected stream (incorporates
    changes from Guard RTMP sink NIFs against closed or unready streams #132)
  • checks for a missing connection before adding a stream in init_*_stream, so a failed
    call does not change the state
  • removes the closed field as it is redundant with output_ctx (i.e. output_ctx is NULL
    only when the stream is closed)
  • removes is_ready, each init_*_stream checks the other stream directly
  • adds native tests for the new error cases
  • bump to v0.29.9

@varsill
varsill requested a review from mat-hek November 4, 2026 16:46
@varsill varsill self-assigned this Nov 5, 2026
@varsill varsill added this to Smackore Nov 5, 2026
@varsill varsill moved this to In Review in Smackore Nov 5, 2026
Return an error from every NIF entry point once the output context is freed,
refuse to write frames before the FLV header exists, and raise instead of
handing FFmpeg a NULL connection when the header or trailer would be written
before try_connect. Based on #132.
A NULL output context already means the stream is closed.
@mat-hek
mat-hek removed their request for review November 9, 2026 12:50
@varsill
varsill requested a review from mat-hek November 9, 2026 12:57
int trailer_err = av_write_trailer(state->output_ctx);
close_output(state);
if (trailer_err) {
return unifex_raise(env, "Failed writing stream trailer");

@mat-hek mat-hek Nov 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you changed all raises to returned errors, maybe change this place too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this one, thanks for spotting 👍

@varsill
varsill merged commit 6aaafe3 into master Nov 9, 2026
4 checks passed
@varsill
varsill deleted the rtmp-sink-close-on-trailer-error branch November 9, 2026 14:30
@github-project-automation github-project-automation Bot moved this from In Review to Done in Smackore Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants