Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kmcgrady
Copy link
Collaborator

@kmcgrady kmcgrady commented Nov 19, 2024

Describe your changes

We hit race conditions where the session info is cleared (on disconnect) and reconnected before a page profile message is sent. We've hit multiple issues with this, so the safest option is to not completely delete the sessionInfo. In the event of the page profile, the message is sent with the latest information it knows. We save the connection state in the session info and update it to be disconnected on disconnect. It will reset once a new NewSession message arrives.

GitHub Issue Link (if applicable)

closes #9767

Testing Plan

  • Unit tests are updated

Contribution License Agreement

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

@kmcgrady kmcgrady added security-assessment-completed Security assessment has been completed for PR change:chore PR contains maintenance or housekeeping change impact:users PR changes affect end users labels Nov 19, 2024
appId = this.sessionInfo.current.appId
sessionId = this.sessionInfo.current.sessionId
pythonVersion = this.sessionInfo.current.pythonVersion
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might need to inform the data team that there will be a risk of page profiles with missing appId/sessionId/pythonVersion since it might be something that breaks some piplines/apps. Or maybe it's easier to just not send the page profile if session info is not available since it might not be very useful anyway (I believe the appId is quite important for many metric apps).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also maybe it makes sense to show a warning via logWarning in case session state is not set yet

@snyk-io
Copy link
Contributor

snyk-io bot commented Mar 24, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-9886/streamlit-1.44.0-py3-none-any.whl
🕹️ Preview app pr-9886.streamlit.app (☁️ Deploy here if not accessible)

@kmcgrady kmcgrady changed the title Add guards for SessionInfo to avoid error message Keep SessionInfo active after initialization, but include connection information Mar 25, 2025
@@ -1159,7 +1175,7 @@ export class App extends PureComponent<Props, State> {
/**
* Performs one-time initialization. This is called from `handleNewSession`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe also adapt the comment that this initialization can happen on the first connection or on a reconnection.


requestFileURLs = (requestId: string, files: File[]): void => {
if (this.isServerConnected()) {
if (this.isServerConnected() && this.sessionInfo.isSet) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe we log to console a warning that the server is not connected or the session info is not set.

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 👍 One nit: maybe you can move the three properties up to the Common Event Fields in the Metrics.proto:

@kmcgrady kmcgrady requested a review from a team as a code owner March 26, 2025 17:27
@kmcgrady kmcgrady merged commit 7670847 into develop Mar 26, 2025
33 checks passed
@kmcgrady kmcgrady deleted the fix/SessionInfo branch March 26, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:chore PR contains maintenance or housekeeping change impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad message format: Tried to use SessionInfo before it was initialized

4 participants