-
Notifications
You must be signed in to change notification settings - Fork 8
Complete pending server-initiated request promises on default executor #43
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
Changes from 2 commits
fe73a2c
85d1a8a
6add493
58139e1
6aaf086
3de5ded
cb24771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ | |
;; client. This cannot be `(-> (p/deferred) (p/catch))` because that returns | ||
;; a promise which, when cancelled, does nothing because there's no | ||
;; exception handler chained onto it. Instead, we must cancel the | ||
;; `(p/deffered)` promise itself. | ||
;; `(p/deferred)` promise itself. | ||
(p/catch p CancellationException | ||
(fn [_] | ||
(protocols.endpoint/send-notification server "$/cancelRequest" {:id id}))) | ||
|
@@ -351,9 +351,16 @@ | |
(if-let [{:keys [p started] :as req} (get pending-requests id)] | ||
(do | ||
(trace this trace/received-response req resp started now) | ||
(if error | ||
(p/reject! p (ex-info "Received error response" resp)) | ||
(p/resolve! p result))) | ||
;; Note that we are called from the server's pipeline, a core.async | ||
;; go-loop, and therefore must not block. Callbacks of the pending | ||
;; request's promise will be executed in the completing thread, | ||
;; which should not be our thread. This is very easy for users to | ||
;; miss, therefore we complete the promise on the default executor. | ||
(p/thread-call :default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for users to be using the default executor as well? And are we sure that our thread isn't in the default executor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not sure if I understand what you mean. Of course they can use the default executor, but there are caveats:
It does not matter which thread executes the original
Yes, as we are called from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Got it. That makes sense.
I guess my question was whether we're causing problems for our users, by having them to execute their callbacks in the default executor (the common fork-join pool). If they already have a lot of stuff going on in that executor, could it lead to other issues for them? If so, what would we do? Is this materially better or worse for them than what we had before? I lack the familiarity with the underlying tools to answer those questions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the current behaviour is definitely worse, since right now we run code that can potentially block in a thread pool that is not designed for this. In general, I think But sure, it would make sense to allow users to specify the executor for responses. I will update this PR to make it configurable. |
||
(fn [] | ||
(if error | ||
(p/reject! p (ex-info "Received error response" resp)) | ||
(p/resolve! p result))))) | ||
(trace this trace/received-unmatched-response resp now))) | ||
(catch Throwable e | ||
(log-error-receiving this e resp)))) | ||
|
Uh oh!
There was an error while loading. Please reload this page.