Skip to content

fix(video): remove explicit frame flushing to avoid segfault due to racecondition#5257

Open
Kishi85 wants to merge 1 commit into
LizardByte:masterfrom
Kishi85:remove-video-frame-flushing-on-destruction
Open

fix(video): remove explicit frame flushing to avoid segfault due to racecondition#5257
Kishi85 wants to merge 1 commit into
LizardByte:masterfrom
Kishi85:remove-video-frame-flushing-on-destruction

Conversation

@Kishi85
Copy link
Copy Markdown
Contributor

@Kishi85 Kishi85 commented Jun 6, 2026

Description

This PR aims to fix #4943 by removing the frame flushing on ~avcodec_encode_session_t() which can result in a segfault due to FFmpeg hw_base_encode expecting ctx->pic_end to never be null but Sunshine seems to break that assumption in this case sometimes (likely due to a racecondition somewhere in FFmpeg as it segfaults on the hw level).

From a logical standpoint it's not strictly necessary to explictly flush the frames here as the avcodec_ctx used to flush the frames is by itself reset and destroyed in the next statement (therefore FFmpeg cleaning up here by itself?). This restores the behaviour back to what was in use for FFmpeg versions before 8.0.

I've tested this for a few days and cannot see any adverse effects from removing this section but as this change is a global one it should be thoroughly tested before merging.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • [] Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@Kishi85 Kishi85 changed the title fix(video): remove frame flushing on destruction to avoid segfault due to racecondition fix(video): remove frame flushing to avoid segfault due to racecondition Jun 6, 2026
@Kishi85 Kishi85 force-pushed the remove-video-frame-flushing-on-destruction branch from ec0fcc7 to 4ccc01b Compare June 6, 2026 08:14
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 6, 2026

@Kishi85 Kishi85 changed the title fix(video): remove frame flushing to avoid segfault due to racecondition fix(video): remove explicit frame flushing to avoid segfault due to racecondition Jun 6, 2026
@ReenigneArcher ReenigneArcher requested a review from cgutman June 6, 2026 23:04
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Bundle Report

Bundle size has no change ✅

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.

Coredump with SIGSEGV when switching displays

1 participant