clj-reload icon indicating copy to clipboard operation
clj-reload copied to clipboard

defonce flushed on 2nd reload

Open nimaai opened this issue 6 months ago • 3 comments
trafficstars

Hi

i have a weird issue with defonce. On 1st reload the value is kept, on 2nd one it is flushed. Here is the source https://github.com/Madek/madek-api-v2/blob/mk/reload-no-ci/src/madek/api/main.clj#L78

So, after 1st reload https://github.com/Madek/madek-api-v2/blob/mk/reload-no-ci/src/madek/api/main.clj#L102 is executed because the value is still there but after 2nd reload it is (atom nil) again.

All i did in regards to the setup is here: https://github.com/Madek/madek-api-v2/commit/dfce73a69f45c430c7bece325befb2185a510044

The service can be run with ./bin/dev-run-backend

Any help would be appreciated. Thanks.

nimaai avatar May 12 '25 13:05 nimaai

[~/work/madek-api-v2] ./scripts/start-dev-server
+ lein clean
Couldn't find project.clj, which is needed for clean

tonsky avatar May 12 '25 13:05 tonsky

Running

clj -M -m madek.api.main

just straight up terminates the process

tonsky avatar May 12 '25 13:05 tonsky

@tonsky due to THROWABLE: org.postgresql.util.PSQLException: FATAL: database "madek" does not exist

please createdb madek and try again

nimaai avatar May 13 '25 11:05 nimaai

I'm seeing the same issue. Here's a simple reproduction:

a.clj:

(ns a
  (:require [b :refer [bar]]))

(defonce foo (atom nil))

(defn set-foo []
  (reset! foo bar))

(comment
  (set-foo)
  @foo)

b.clj:

(ns b)

(def bar 12)

After evaluating (set-foo), @foo is 12. Change bar in b.clj to a different number, save then run (reload/reload), @foo is still 12. Change bar again, save then reload, @foo is now nil.

ntharim avatar May 19 '25 07:05 ntharim

Thanks! Will look into it

tonsky avatar May 19 '25 16:05 tonsky

Should be fixed in 0.9.7

tonsky avatar May 21 '25 13:05 tonsky