Skip to content

Commit

Permalink
Fix out of order state update messages (#3010)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Aug 24, 2024
1 parent 2d5b9bb commit aaa835b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,23 @@ all patches: ${JSON.stringify(patches, null, 1)}

this.apply_notebook_patches = apply_notebook_patches
// these are update message that are _not_ a response to a `send(*, *, {create_promise: true})`
this.last_update_counter = -1
const check_update_counter = (new_val) => {
if (new_val <= this.last_update_counter) {
console.error("State update out of order", new_val, this.last_update_counter)
alert("Oopsie!! please refresh your browser and everything will be alright!")
}
this.last_update_counter = new_val
}

const on_update = (update, by_me) => {
if (this.state.notebook.notebook_id === update.notebook_id) {
const show_debugs = launch_params.binder_url != null
if (show_debugs) console.debug("on_update", update, by_me)
const message = update.message
switch (update.type) {
case "notebook_diff":
check_update_counter(message?.counter)
let apply_promise = Promise.resolve()
if (message?.response?.from_reset) {
console.log("Trying to reset state after failure")
Expand Down
12 changes: 8 additions & 4 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ const current_state_for_clients = WeakKeyDict{ClientSession,Any}()
const current_state_for_clients_lock = ReentrantLock()
const update_counter_for_debugging = Ref(0)

const update_counter_for_clients_1 = WeakKeyDict{ClientSession,Any}()
const update_counter_for_clients_2 = WeakKeyDict{ClientSession,Any}()
const update_counter_for_clients_3 = WeakKeyDict{ClientSession,Any}()

"""
Update the local state of all clients connected to this notebook.
"""
Expand Down Expand Up @@ -195,12 +199,12 @@ function send_notebook_changes!(πŸ™‹::ClientRequest; commentary::Any=nothing)
end
end
end
end

for (client, msg) in outbox
putclientupdates!(client, msg)
for (client, msg) in outbox
putclientupdates!(client, msg)
end
try_event_call(πŸ™‹.session, FileEditEvent(πŸ™‹.notebook))
end
try_event_call(πŸ™‹.session, FileEditEvent(πŸ™‹.notebook))
end

"Like `deepcopy`, but anything other than `Dict` gets a shallow (reference) copy."
Expand Down

0 comments on commit aaa835b

Please sign in to comment.