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

Deref in task causing a silent Interrupted Exception #107

Closed
yenda opened this issue Apr 17, 2024 · 2 comments
Closed

Deref in task causing a silent Interrupted Exception #107

yenda opened this issue Apr 17, 2024 · 2 comments

Comments

@yenda
Copy link
Contributor

yenda commented Apr 17, 2024

Even if the exception is caught and the deref is in the catch:

(defn task []
  (m/sp
    (try
      (m/? (m/reduce
            (constantly nil)
            (m/ap (let [s (m/?> (m/seed [1 2 3]))]
                    (m/? (m/via m/blk (throw (ex-info "BOOM" {}))))))))
      (catch Exception e
        (println "Catching the exception")
        @(future (println "Printing in future"))
        (println "Never prints")))))

((task) (constantly nil) (constantly nil))

while:

(defn task []
  (m/sp
    (m/? (m/reduce
          (constantly nil)
          (m/ap (let [s (m/?> (m/seed [1 2 3]))]
                  (m/? (m/via m/blk (println s)))))))
    @(future (println "Printing in future"))
    (println "Does prints")))

((task) (constantly nil) (constantly nil))
@yenda yenda changed the title Deref in task causing Interrupted Exception when ran in newVirtualThreadPerTaskExecutor Deref in task causing a silent Interrupted Exception Apr 17, 2024
@yenda
Copy link
Contributor Author

yenda commented Apr 17, 2024

Adding this snippet as well, deref works outside the catch:

((m/sp
   (try
     (m/? (m/reduce
           (constantly nil)
           (m/ap (let [s (m/?> (m/seed [1 2 3]))]
                   (m/? (m/via m/blk (throw (ex-info "BOOM" {}))))))))
     (catch Exception e
       (println "Catching the exception")
       (try
         @(future (println "Printing in future"))
         (catch Exception _
           (println "The deref blew up but we catch it")))
       (println "This would never print without catching the exception from deref")))
   @(future (println "Printing in future outside catch"))
   (println "And this prints because the deref above doesn't blow up"))
 (constantly nil) (constantly nil))

@leonoel
Copy link
Owner

leonoel commented Apr 17, 2024

Fixed in b.37. via continuations are now called after clearing the interruption flag, such that interruptible user code is not interrupted.

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

No branches or pull requests

2 participants