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

Add reset-executor! and shutdown-executor! to re-frame.interop #810

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lowecg
Copy link

@lowecg lowecg commented Nov 17, 2024

For #809

Executor Service Lifecycle Management
Added two functions to manage the executor service lifecycle in re-frame/interop:

reset-executor! - Creates a fresh single-threaded executor when needed
shutdown-executor! - Cleanly terminates the executor with configurable timeout

Why?
These functions enable proper cleanup in short-lived processes like AWS Lambda, CLI runs and tests. Without explicit shutdown, the non-daemon executor threads prevent the JVM from exiting cleanly.

Adding the following to a test ensures clean shutdown:

(ns my-ns
  (:require
    [clojure.test :refer :all]
    [re-frame.interop :as interop]
    ...))

(use-fixtures :once
              (fn [f]
                (f)  ; runs all tests
                (interop/shutdown-executor! 100)))

@kimo-k
Copy link
Contributor

kimo-k commented Dec 2, 2024

@lowecg
Copy link
Author

lowecg commented Dec 2, 2024

I've removed reset-executor! from the PR. Lambda functions work fine without interacting with the scheduler

@lowecg
Copy link
Author

lowecg commented Dec 4, 2024 via email

@p-himik
Copy link
Contributor

p-himik commented Dec 4, 2024

@lowecg Ah, sorry for the noise - I removed my message pretty much immediately after I realized that I've posted it on the PR and not on the issue page.

As for what to do - that would be up to @kimo-k or someone else from Day8. But were it my own PR, I would definitely go the route of removing the executor, the thread for next-tick, and the associated locking that was added only to make the thread behave properly.

@kimo-k
Copy link
Contributor

kimo-k commented Dec 5, 2024

Regarding locking: #469 #471

@lowecg
Copy link
Author

lowecg commented Dec 7, 2024

@p-himik @kimo-k Thank you for your continued input on this. I've removed the executor and locking added for #471. The change fixes the repo cases I'd raised for #809. I've left the test from #469 since it shows the simplified next-tick is working as intended in this regard.

Here's a short summary for the change, I hope it sufficiently captures your thread on Slack:

The single-threaded executor in the JVM implementation of re-frame is being removed to simplify the code and resolve concurrency issues. Originally added to mimic JavaScript’s single-threaded behaviour, it introduced unnecessary complexity and inconsistent behaviour, such as race condition, unpredictable event handling orders and process hang when running tests from the CLI.

Benefits to removing the executor:

  • Simpler Code: Eliminates threading and locking overhead.
  • Consistent Behaviour: Aligns more closely with JavaScript semantics.
  • Improved Reliability: Reduces concurrency issues in tests and development.
  • Streamlined Focus: Keeps re-frame’s JVM use focused on testing, avoiding unsupported multithreaded scenarios.

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.

3 participants