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

[in-progress] Protect datalog cache from early cancellation #657

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dwwoelfel
Copy link
Contributor

This prevents in-progress datalog queries from getting cancelled when there are multiple sessions waiting on the query.

Previously, we could get into a situation like this:

  1. user-1 opens a session and runs query-a
  2. user-2 opens a session and runs query-a
  3. user-1 closes their session
  4. we cancel all in-progress queries, including query-a
  5. user-2 gets an error for query-a because the query was cancelled

This PR moves the query execution to a separate call stack where it won't get canceled if the parent is canceled.

To keep the behavior where we cancel queries that exceed the handle-receive-timeout-ms, we add another future that is in the call stack. If it gets canceled and there are no other threads waiting on the query, then it will cancel the query.

Copy link

View Vercel preview at instant-www-js-dont-cancel-jsv.vercel.app.

@@ -342,23 +347,112 @@
;; ------
;; datalog cache

(defn swap-datalog-cache-delay! [conn app-id datalog-query delayed-call]
(defn swap-datalog-cache! [conn app-id datalog-query-fn ctx datalog-query]
Copy link
Contributor

Choose a reason for hiding this comment

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

🤯 I salute you sir.

;; We added it, so we must execute it
(let [stmt-tracker (sql/make-top-level-statement-tracker)
result-promise (:promise @result-delay)
work-fut (binding [ua/*child-vfutures* nil ;; Move future to a new "call-stack"
Copy link
Contributor

Choose a reason for hiding this comment

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

Man, bind + statement-tracker makes for a really powerful abstraction.

Copy link
Contributor

@stopachka stopachka left a comment

Choose a reason for hiding this comment

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

Beautiful work @dwwoelfel !

q))]
@started
(future-cancel f1)
(is (instance? java.lang.InterruptedException (deref err 100 :timeout)))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah interesting, so err is taking more than 100ms to deliver. 🤔

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.

2 participants