Skip to content

Fix tab switching crash when creating new tabs (Issue #7716) #7761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

mbergo
Copy link
Contributor

@mbergo mbergo commented Apr 20, 2025

Fix tab switching crash when creating new tabs (Issue #7716)

Problem:
The Zen browser was experiencing random crashes when switching tabs, particularly
when creating a new tab with Ctrl+T and typing a URL. The crash logs showed
"CompositorBridgeChild receives IPC close with reason=AbnormalShutdown" errors,
indicating issues with the graphics compositor during tab switching operations.
This was caused by race conditions in the tab switching code and lack of proper
error handling when dealing with browser elements that might be in an invalid state.

Solution:
Instead of just catching errors, we've implemented a more robust solution that addresses
the root causes of the race conditions in the tab switching code:

1. State Management System:
   - Added a queue-based system for tab operations to ensure they execute in sequence
   - Implemented debouncing to prevent rapid tab switching that could cause race conditions
   - Added state validation before operations to ensure browser elements are in a valid state

2. Asynchronous Operation Handling:
   - Used Promises and async/await for proper sequencing of operations
   - Added proper timing controls with small delays to ensure DOM is ready
   - Implemented a mutex-like approach to prevent concurrent workspace changes

3. Robust Tab State Validation:
   - Added comprehensive checks for tab validity before operations
   - Implemented proper cleanup of resources to prevent memory leaks
   - Added validation for browser window state to prevent operations on closed windows

4. Improved Error Recovery:
   - Added fallback mechanisms when operations fail
   - Implemented proper cleanup of state even when errors occur
   - Added more informative error messages for better debugging

These changes make the browser much more robust when handling tab switching operations,
preventing the crashes reported in issue #7716.

@mbergo mbergo requested a review from mauro-balades as a code owner April 20, 2025 03:40
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Bug labels Apr 20, 2025
@mbergo mbergo force-pushed the fix-tab-switching-crash branch 2 times, most recently from f0a0a27 to 7ed1ebc Compare April 20, 2025 03:50
@mauro-balades
Copy link
Member

Shoudnt we rather tackle down the race condition rather than adding error handlers?

@mbergo
Copy link
Contributor Author

mbergo commented Apr 20, 2025

Shoudnt we rather tackle down the race condition rather than adding error handlers?

Yes, sorry about it. I will get back to you with a better proposal. Thanks @mauro-balades

@mbergo mbergo force-pushed the fix-tab-switching-crash branch from 7ed1ebc to bf2f647 Compare April 21, 2025 04:58
Problem:
The Zen browser was experiencing random crashes when switching tabs, particularly
when creating a new tab with Ctrl+T and typing a URL. The crash logs showed
"CompositorBridgeChild receives IPC close with reason=AbnormalShutdown" errors,
indicating issues with the graphics compositor during tab switching operations.
This was caused by race conditions in the tab switching code and lack of proper
error handling when dealing with browser elements that might be in an invalid state.

Solution:
Instead of just catching errors, we've implemented a more robust solution that addresses
the root causes of the race conditions in the tab switching code:

1. State Management System:
   - Added a queue-based system for tab operations to ensure they execute in sequence
   - Implemented debouncing to prevent rapid tab switching that could cause race conditions
   - Added state validation before operations to ensure browser elements are in a valid state

2. Asynchronous Operation Handling:
   - Used Promises and async/await for proper sequencing of operations
   - Added proper timing controls with small delays to ensure DOM is ready
   - Implemented a mutex-like approach to prevent concurrent workspace changes

3. Robust Tab State Validation:
   - Added comprehensive checks for tab validity before operations
   - Implemented proper cleanup of resources to prevent memory leaks
   - Added validation for browser window state to prevent operations on closed windows

4. Improved Error Recovery:
   - Added fallback mechanisms when operations fail
   - Implemented proper cleanup of state even when errors occur
   - Added more informative error messages for better debugging

These changes make the browser much more robust when handling tab switching operations,
preventing the crashes reported in issue zen-browser#7716.
@mbergo mbergo force-pushed the fix-tab-switching-crash branch from bf2f647 to 263db42 Compare April 21, 2025 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants