Skip to content

Conversation

@raethlein
Copy link
Collaborator

@raethlein raethlein commented Jan 9, 2025

Describe your changes

Related to #9921 and extracted from PR #9965
Related to #10132

In #10130, we stopped raising a RuntimeError when a fragment with a specified id cannot be found. This solves the original issue in #9921, but surfaced a different issue where the dialog did not always close when the button in the dialog was clicked in fast succession.

The reason for this is that in app_session, a fragment run might create a new ScriptRunner when the current ScriptRunner is in state STOPPED (in this case, success here is false and the new ScriptRunner is created). This will lead to all events from the previous script runner being ignored (see here). When the full app rerun ScriptRunner is done (STOPPED) but its events are not processed before the new ScriptRunner is created, its finished message is not sent to the frontend and no cleanup is happening.

GitHub Issue Link (if applicable)

Testing Plan


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@raethlein raethlein changed the title Prevent potential race condition Don't update ScriptRunner for fragments that do not exist anymore Jan 9, 2025
@raethlein raethlein added security-assessment-completed Security assessment has been completed for PR impact:internal PR changes only affect internal code change:bugfix PR contains bug fix implementation labels Jan 9, 2025
@raethlein raethlein requested a review from lukasmasuch January 9, 2025 17:18
@raethlein raethlein marked this pull request as ready for review January 10, 2025 09:21
@raethlein raethlein changed the title Don't update ScriptRunner for fragments that do not exist anymore Don't request_rerun for fragments that do not exist anymore Jan 10, 2025
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@raethlein raethlein merged commit 8ccd745 into develop Jan 10, 2025
33 checks passed
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
…t#10147)

## Describe your changes

We stopped raising
a RuntimeError when a fragment with a specified id cannot be found. This
solves the original issue in
streamlit#9921, but surfaced a
different issue where the dialog did not always close when the button in
the dialog was clicked in fast succession.

The reason for this is that in app_session, a fragment run might create
a new ScriptRunner when the current ScriptRunner is in state STOPPED
is false and the new ScriptRunner is created). This will lead to all
events from the previous script runner being ignored.
When the full app rerun ScriptRunner is done (STOPPED) but its events
are not processed before the new ScriptRunner is created, its finished
message is not sent to the frontend and no cleanup is happening.

## GitHub Issue Link (if applicable)

## Testing Plan

- Unit Tests (JS and/or Python)
- Add unit test to ensure that the scriptrunner is not requested if the
fragment does not even exist anymore
- E2E Tests
- The e2e test that was added in
streamlit#10132 _could_ catch this one
here, although it happens more rarely than the race condition tackled in
that PR

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
@lukasmasuch lukasmasuch deleted the fix/issue-9921-3 branch March 13, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:internal PR changes only affect internal code security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants