Skip to content

test(engine): the cut audio link test cuts the read under load too - #8825

Open
miguel-heygen wants to merge 3 commits into
mainfrom
test/url-read-cut-under-load
Open

miguel-heygen wants to merge 3 commits into
mainfrom
test/url-read-cut-under-load

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

"fails the track when the read is cut mid-span, instead of padding it with silence" in packages/engine/src/services/audioMixer.urlRead.test.ts now cuts the read however ffmpeg orders its requests, so it no longer passes or fails with machine load.

Why

The test's range server cut the first read that started at or after one second into the file. Normally the mix's ffmpeg seeks to second 2 with a new request, which the server cuts at second 6. Under load, the server has already written much of an earlier open-ended answer (the one starting at byte 78) into the socket buffers, and ffmpeg reads on through it instead of seeking. That answer started before the cut point, so it was served whole, and the mix correctly succeeded: the test failed on expect(result.success).toBe(false).

Logged request ranges from a failing run: bytes=0-, bytes=78- (probes), bytes=3648078-, bytes=0-, bytes=78-, and no read at or after one second. A passing run has the extra bytes=384078-, which the server cuts.

How

The cut server now caps each answer at SERVED_RANGE_BYTES (1 MiB), the cap the byte-counting server in the same file already uses. To read past 1 MiB, ffmpeg has to ask again, and that request starts between one second and the cut point, so it is cut whichever way ffmpeg reads. Product code is unchanged.

Test plan

  • On the devbox, 16 runs at a time at load ~12: before, 12 of 48 runs of this test failed; after, 0 of 48, and the whole file passed 32 of 32.
  • With -xerror removed from extractAudioSegment in packages/engine/src/services/audioMixer.ts (the fix(engine): cloud renders fail instead of going silent when an audio read is cut off #5996 fix this test guards), the test still fails: expected true to be false.
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix: "fails the track when the read is cut mid-span, instead of padding it with silence" in packages/engine/src/services/audioMixer.urlRead.test.ts fails 12 of 48 runs on main b975bbe under parallel load; with this change it fails only when -xerror is removed.

The cut server keyed its cut on where a read starts. Under load ffmpeg read on through an earlier
open-ended answer instead of seeking, so the cut never fired and the mix rightly succeeded. The cut
server now caps each answer like the counting one, so every read past the cut point is cut.

@terencecho terencecho 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.

Changes requested at cb962303.

P2 packages/engine/src/services/audioMixer.urlRead.test.ts:54 — The capped response can satisfy the failure assertion without reaching the fixture's simulated cut. If FFmpeg reads through the response starting at byte 78, that response ends at byte 1,048,654, before the intended cut at 1,152,000. The pinned Linux FFmpeg can report an I/O error at the short response without making another request because the fixture's plain HTTP input has reconnect disabled. Cut the active response at the intended offset on the read-through path and assert that the simulated cut fired. Pinned FFmpeg HTTP read path

The PR body names the regression. This finding is from static review. I did not rerun the load or mutation tests.

— tai (automated review)

… and the test checks it did

Capping answers let ffmpeg fail at a short answer before the cut fired, in 12 of 48 runs under
load. The link now ends at the cut point for every answer that starts before it, and the test
asserts the cut fired.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Addressed at 97f3003. You were right: with the cut test asserting that the cut fired, the capped version failed that assertion in 12 of 48 runs under load (16 at a time, load ~15). ffmpeg stopped at the end of a capped answer and the mix failed without the cut ever firing.

The cap is gone from the cut server. With cut, the link now dies at cut.at for every answer that starts before it: the server writes up to cut.at and drops the connection, whether the read is ffmpeg's seek to second 2 or its read-through from byte 78. The "refuse every later request" rule is gone too, because it would refuse the probe's tail read near byte 3,648,078. The header probes are cut as well, but they only need the first 78 bytes and close first. There is no other early end, so a failed mix can only come from the cut, and the test asserts cut.fired.

The body was written for cb96230 and is frozen under the legal hold, so this comment replaces its How and Test plan:

  • 48 runs of the whole file, 16 at a time at load ~18: 0 failed, every run 5/5, the cut fired in each.
  • With -xerror removed from extractAudioSegment in packages/engine/src/services/audioMixer.ts, the test fails: expected true to be false.

fails without the fix: "fails the track when the read is cut mid-span, instead of padding it with silence" in packages/engine/src/services/audioMixer.urlRead.test.ts fails 12 of 48 runs on main b975bbe under parallel load (the mix succeeds), and at cb96230 its new cut.fired assertion fails in 12 of 48.

@terencecho terencecho 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.

[P2] The cut assertion can be satisfied before extraction reads the URL (packages/engine/src/services/audioMixer.urlRead.test.ts:163)

The new fixture fixes both FFmpeg read paths. It also sets cut.fired during the metadata probe, and does so before the response write completes. I verified that the test still passes with the extractor forced to exit before opening the URL: the probe sets the bit and the unrelated extraction failure maps to prepare/download_failed. Please assert that the extraction read encountered the cut, for example by checking the premature HTTP EOF in the reported FFmpeg failure.

All five tests passed locally with the pinned Linux FFmpeg. Separate seek and read-through checks with that binary failed on the cut with -xerror and succeeded without it. Windows CI was still running.

— tai (automated review)

…the cut

The metadata probe also reads through the cut, so a flag the server set proved nothing about the
extraction. The test now checks the extraction's own failure names the premature end at the cut.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Addressed at 8ad6f01. Right: the metadata probe's read also crosses the cut, so cut.fired said nothing about extraction.

The fired flag is gone. The test now checks the extraction's own failure: result.failures[0].detail must contain Stream ends prematurely at ${cut.at}, the error FFmpeg's HTTP reader prints in that failure when its read is cut at byte 1,152,000. Only an extraction read that reached the cut produces it.

  • Red-first, with extraction forced to fail before it opens the URL (-f no_such_demuxer added to its URL arguments in extractAudioSegment, which still reports download_failed): the 97f3003 test passes; this one fails with expected '(ran 29 ms, limit 300000 ms) FFmpeg e…' to contain 'Stream ends prematurely at 1152000'.
  • 48 runs of the whole file, 16 at a time at load ~25: 0 failed, every run 5/5.
  • With -xerror removed, the test still fails (expected true to be false).

fails without the fix: "fails the track when the read is cut mid-span, instead of padding it with silence" in packages/engine/src/services/audioMixer.urlRead.test.ts fails 12 of 48 runs on main b975bbe under parallel load; at 97f3003 it passes even when extraction never opens the URL.

This branch has not been deployed

No deployments
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