Skip to content
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

Send initialization data in the NewReport message #2317

Merged

Conversation

tconkling
Copy link
Contributor

@tconkling tconkling commented Nov 4, 2020

Removes ForwardMsg.initialize. All initialization data is now carried in every ForwardMsg.new_report message.

This lets us remove the state from the server that stores whether a given client has already received the initialize message. This flag had a race condition - it was possible for the flag to be set to true, but the client not to actually have received the message, if a script used the st.experimental_rerun function towards the top of a script.

  • (Python) report_session. _maybe_enqueue_initialize_message (and its associated flag) is gone.
  • (frontend) App.handleNewReport now conditionally calls through to a new App.handleOneTimeInitialization function for the first new report message. There's logic that detects and errors if the initialize data unexpectedly changes from message to message.
  • (frontend) Several new App.test.tsx tests that make sure initialization/newReport handling is correct.

Fixes #2226

@tconkling tconkling requested a review from a team November 4, 2020 23:31
Comment on lines -34 to -41
fileName: "",
recording: false,
recordAudio: false,
countdown: -1,
startAnimation: false,
showRecordedDialog: false,
showScreencastDialog: false,
showUnsupportedDialog: false,
Copy link
Contributor Author

@tconkling tconkling Nov 4, 2020

Choose a reason for hiding this comment

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

Unrelated to this PR, but I was making changes to App.tsx - none of these props exist

* develop:
  Note about using recent versions of Streamlit for sharing (streamlit#2326)
  Bump sphinx from 3.2.1 to 3.3.0 in /lib (streamlit#2320)
  Some grammatical changes in Readme (streamlit#2267)
  exclude v50 (streamlit#2307)
This is totally legit - it happens when the Streamlit server is killed and restarted, and the client reconnects.

Test SessionInfo.fromInitializeMessage
Comment on lines -381 to -386
/**
* Handler for ForwardMsg.initialize messages
* @param initializeMsg an Initialize protobuf
*/
handleInitialize = (initializeMsg: Initialize): void => {
const {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic now lives in the "handleOneTimeInitialization" function

Copy link
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

Very clean. Mostly questions and a small suggestion. Looks good overall!

frontend/src/lib/SessionInfo.test.ts Outdated Show resolved Hide resolved
frontend/src/lib/SessionInfo.ts Outdated Show resolved Hide resolved
!config ||
!sessionState
) {
throw new Error("InitializeMsg is missing a required field")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm assuming this part isn't necessary now. Are we just assuming the correct message is sent down (totally fine, but just checking)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these checks happen within the SessionInfo constructor, so this was just essentially duplicate logic

@@ -530,9 +471,24 @@ export class App extends PureComponent<Props, State> {
* @param newReportProto a NewReport protobuf
*/
handleNewReport = (newReportProto: NewReport): void => {
const initialize = newReportProto.initialize as Initialize
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity, does the protobuf not return the correct type here?

Copy link
Contributor Author

@tconkling tconkling Nov 10, 2020

Choose a reason for hiding this comment

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

this is the larger protobufjs typescript issue: message fields are typed as interfaces, not classes (IInitialize instead of Initialize), and the interface typings claim that fields can be undefined - when in fact, for a deserialized protobuf, there's no such thing as an undefined field (because anything not explicitly defined gets assigned a default value). So the cast here prevents us from doing a whole lot of non-null assertions on the message fields.

@tconkling tconkling merged commit ece41b7 into streamlit:develop Nov 10, 2020
@tconkling tconkling deleted the tim/AllowMultipleInitializeMessages branch November 10, 2020 17:39
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.

Script rerun event can cause SessionInfo not initialized error on the frontend
2 participants