Skip to content

fix: release resources on failed setup, rejected tasks and oversized sends - #506

Merged
devopvoid merged 6 commits into
mainfrom
fix/native-resource-robustness
Nov 1, 2026
Merged

devopvoid merged 6 commits into
mainfrom
fix/native-resource-robustness

Conversation

@devopvoid

Copy link
Copy Markdown
Owner
  • Release the reader and media sources when opening a MediaFileSource fails before the player exists; MediaPlayer reads the source handles before it takes the reader over.
  • Check every JNI allocation in I420Buffer::toJava and hand over the native reference only once the wrapper exists, also in the video sink and desktop capture callback.
  • Release waiting media and clear the scheduled state when the executor rejects a dispatcher task.
  • Reserve the data channel send limit before copying a message, and give it back when the copy fails.
  • Keep hash codes of native wrappers stable after disposal, so disposed wrappers stay findable in hash sets.
  • Remove cancelled timeouts from the runtime schedulers right away.

The reader and both media sources are made inside the guarded block, so a failure before the player exists, such as a source whose native library cannot be loaded, no longer leaves the file open. MediaPlayer reads the source handles before it detaches the reader, which the caller then still closes.
I420Buffer::toJava checks each direct buffer and the wrapper as it is made, holds them in JavaLocalRefs and sets the handle last. The video sink and the desktop capture callback take the frame's reference only once the wrapper exists, and give it back when the frame cannot be made.
The dispatcher submits its task with a fallback that releases what waits, counts it as dropped and clears the scheduled flag, so the next item offered tries the executor again.
Arrays and buffers take their size out of the limit before they are copied, and give it back when the copy fails, so a message too large for the limit is refused without the memory of a copy. Text longer than the limit is refused before it is encoded.
Wrappers that compare native handles hash by the handle they had when first hashed, kept for their whole life, so a disposed wrapper is still found in the set it was added to. Equality is unchanged: same live native object, or the same instance.
The timer and the audio pacer are ScheduledThreadPoolExecutors with the remove-on-cancel policy, so a timeout cancelled by a completed operation leaves the queue at once instead of when it would have been due.
@devopvoid
devopvoid merged commit 4566607 into main Nov 1, 2026
22 checks passed
@devopvoid
devopvoid deleted the fix/native-resource-robustness branch November 1, 2026 10:35
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.

1 participant