fix: reject session reuse when existing connection is still active#6513
Open
ihmily wants to merge 1 commit into
Open
fix: reject session reuse when existing connection is still active#6513ihmily wants to merge 1 commit into
ihmily wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When running a Flet app in web browser mode, opening the same URL in multiple browser tabs
causes cross-tab session contamination. Events triggered in Tab1 affect Tab2's UI, while
Tab1 becomes unresponsive.
Root cause: The
REGISTER_CLIENThandler inflet_app.pyunconditionally reuses anexisting session when the client provides a matching
session_id, without checking whetherthat session is still actively connected. When a second browser tab inherits the same
_flet_session_idviasessionStoragecloning (standard HTML5 behavior for duplicated tabs),it steals the session's output connection from the original tab via
attach_connection().Fix: Before reusing a session, check if its connection is still alive
(
session.connection is not None). If so, the request is from a different tab — create anew session instead. This preserves legitimate reconnect scenarios (page refresh / network
blip) where
connectionis alreadyNoneafterdisconnect().Fixes #6512
Test Code
Type of change
Bug fix (non-breaking change which fixes an issue)
Checklist
release/*branch, I added a new record to the active rootCHANGELOG.mdsectionScreenshots
Additional details
sdk/python/packages/flet-web/src/flet_web/fastapi/flet_app.pySession.disconnect()sets__conn = Nonebefore any reconnect attempt.Summary by Sourcery
Bug Fixes: