Skip to content

Preserve RTMP chunk stream state on abort - #3515

Open
wasphin wants to merge 1 commit into
apache:masterfrom
wasphin:fix-rtmp-abort-state
Open

Preserve RTMP chunk stream state on abort#3515
wasphin wants to merge 1 commit into
apache:masterfrom
wasphin:fix-rtmp-abort-state

Conversation

@wasphin

@wasphin wasphin commented Sep 1, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: N/A

Problem Summary:

Processing an RTMP Abort command currently deletes the target chunk stream.
This also discards its previous message header, so later compressed chunk
headers cannot be decoded. Ignoring an Abort that targets the currently
parsed chunk stream also leaves the intended state transition implicit.

What is changed and the side effects?

Changed:

Reset the target chunk stream's incomplete message while preserving the chunk
stream and its previous message header. Extend the RTMP regression test to
cover aborting both the current and a different chunk stream.

Side effects:

  • Performance effects: None expected. Abort now resets existing state instead
    of deleting and potentially recreating the chunk stream.

  • Breaking backward compatibility: No.


Check List:

Reset the incomplete message when processing an RTMP Abort command instead
of deleting the chunk stream. This keeps the previous message header needed
by subsequent compressed chunk headers.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts bRPC’s RTMP protocol handling so that an RTMP Abort control message resets a chunk stream’s in-progress (incomplete) message without deleting the chunk stream object, preserving the previous message header needed to decode subsequent compressed chunk headers. It also expands the RTMP regression test to cover aborting both the currently parsed chunk stream and a different chunk stream.

Changes:

  • Replace deletion-based chunk stream clearing with an abort/reset path that preserves the chunk stream and its last header.
  • Add RtmpChunkStream::OnAbort() to reset read-assembly state for a chunk stream.
  • Extend RTMP unit tests to cover abort behavior for both “self” and “other” chunk streams, including split control messages via small inbound chunk size.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/brpc_rtmp_unittest.cpp Expands regression coverage to ensure Abort preserves chunk stream/header state for both same-stream and cross-stream abort targets.
src/brpc/policy/rtmp_protocol.h Renames/clarifies the context API from deletion semantics to abort/reset semantics; adds OnAbort() hook on chunk streams.
src/brpc/policy/rtmp_protocol.cpp Implements abort-as-reset (AbortChunkStream + RtmpChunkStream::OnAbort) and applies it from Abort message handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 869 to 880
SubChunkArray* sub_array =
_cstream_ctx[index1].load(butil::memory_order_consume);
if (sub_array == nullptr) {
LOG(ERROR) << "chunk_stream_id=" << cs_id << " does not exist";
return;
}
const uint32_t index2 = cs_id - index1 * RTMP_CHUNK_ARRAY_2ND_SIZE;
RtmpChunkStream* cstream =
sub_array->ptrs[index2].load(butil::memory_order_consume);
if (cstream == nullptr) {
LOG(ERROR) << "chunk_stream_id=" << cs_id << " does not exist";
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants