Comments (14)
Hi Vesa,
Thanks a lot for narrowing down on the version - that's really helpful. I suspect it might have something to do with a change to the get-hostname
fn introduced in 2.7.0.
Will try look into it later today and get back to you. Cheers! :-)
from timbre.
BTW just to confirm - is this the lein migrate
you're talking about?: https://github.com/pjstadig/migratus
from timbre.
No, it's drift. But happens also with the drop
task which is custom made.
from timbre.
I extracted the get-hostname
code and ran it and can now say the problem is indeed related to that:
(defn memoize-ttl [ttl-ms f]
(let [cache (atom {})]
(fn [& args]
(let [{:keys [time-cached d-result]} (@cache args)
now (System/currentTimeMillis)]
(if (and time-cached (< (- now time-cached) ttl-ms))
@d-result
(let [d-result (delay (apply f args))]
(swap! cache assoc args {:time-cached now :d-result d-result})
@d-result))))))
(def get-hostname
(memoize-ttl 60000
(fn []
(let [p (promise)]
(future ; Android doesn't like this on the main thread
(deliver p
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost"))))
@p))))
(defn drop-db! []
(->
(get-hostname)
(prn)))
This quickly prints the hostname and then takes a minute to exit.
from timbre.
Hi Vessa, sorry for not getting back to you - am a little swamped atm. Appreciate the follow-up.
To clarify: you're saying the print happens quickly, it's just the shutdown that then takes long?
Could you try an alternative on your end?
@(future
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost")))
Does it help if you call (shutdown-agents)
in your app's teardown code?
from timbre.
Another one to try:
(->
(future ; Android doesn't like this on the main thread
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost")))
(deref 5000 "UnknownHost"))
You can just stick that anywhere in your code and see if it hits your shutdown time.
from timbre.
Hi,
No worries, I'm not in a hurry since the old version works just fine. And yes, the print happens quickly.
If I understood correctly you wanted me to try this:
(def get-hostname
(memoize-ttl 60000
(fn []
@(future
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost"))))))
and this:
(defn my-task []
(->
(future ; Android doesn't like this on the main thread
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost")))
(deref 5000 "UnknownHost")
(prn)))
Neither works any better. Calling (shutdown-agents)
does help.
from timbre.
Yeah, that's right - thanks.
Calling (shutdown-agents) does help.
As in helps a little, or completely eliminates the shutdown delay?
from timbre.
Eliminates it completely.
from timbre.
Hmm, this is a bit tricky.
My understanding's a little rough on the details but basically: using the future inits a Clojure thread pool which can negatively impact shutdown time if you don't have a call to shutdown-agents
in your app's termination routine.
You can probably see the same behaviour by adding something simple like @(future (Thread/sleep 2000))
anywhere in your app.
I do recall that there was some talk on the dev list at some point about possibly making this (semi?) automatic - but I don't recall what came of that and can't find the discussion now.
So a short-term solution to work around this:
(defn destroy! [] <... other stuff> (shutdown-agents))
(.addShutdownHook (Runtime/getRuntime) (Thread. ^Runnable destroy!))
That'll make sure Clojure's thread pool gets closed on app shutdown.
I'm not super happy about suggesting that everyone do that though... will need to do a little digging to find out what the current view is on agent shutdown. Won't have the time for a couple days at least, but I'll keep this issue open and get back to you if I come up with a better long-term solution.
Thanks again for bringing this to my attention and with the assistance debugging. Cheers! :-)
from timbre.
I love Timbre, but this issue is confusing for new users. Running the demo causes the console to hang for 60 seconds unless either (shutdown-agents)
or (System/exit 0)
is called.
Scanning the mailing list shows no discussion of switching agents to daemon threads for several years. Is this a dead issue?
Alan
from timbre.
Hi Alan, not a dead issue at all. Have been too swamped lately to investigate possible alternatives - but I'd be very happy to see a PR or suggestions.
I've got a number of changes queued that I'd like to make for an upcoming Timbre v4 release, so I'll likely look closer at this when I'm doing that work - but no ETA unfortunately. Best bet would be a PR if you're looking to see this resolved ASAP.
Cheers! :-)
from timbre.
Actually, I had assumed that a change to Clojure itself would be required
(judging from past mailing list posts). Do you think that it can be fixed
in Timbre itself?
Alan
On Fri, Oct 31, 2014 at 12:05 AM, Peter Taoussanis <[email protected]
wrote:
Hi Alan, not a dead issue at all. Have been too swamped lately to
investigate possible alternatives - but I'd be very happy to see a PR or
suggestions.I've got a number of changes queued that I'd like to make for an upcoming
Timbre v4 release, so I'll likely look closer at this when I'm doing that
work - but no ETA unfortunately. Best bet would be a PR if you're looking
to see this resolved ASAP.Cheers! :-)
—
Reply to this email directly or view it on GitHub
#61 (comment).
from timbre.
Closing this, looks like there's not much that can be done from Timbre's side. Will just document the issue+workaround for now.
from timbre.
Related Issues (20)
- cljs: JS objects are printed uselessly HOT 2
- Update io.aviso/pretty to 1.2 HOT 1
- Support for `nbb` HOT 2
- Community appenders no longer included in 6.0.0 HOT 2
- 6.0.1. breaks in GraalVM native-image HOT 11
- Add test/s re: GraalVM compatibility HOT 1
- Why are my Timbre timezones different than the system ones? HOT 3
- [shadow-cljs] Invalid :refer, var taoensso.encore/have does not exist HOT 26
- IllegalAccessException when logging internal JDK exception (SunCertPathBuilderException) via `log/error` HOT 13
- shadow-cljs: Advanced build bloated since 6.0.3 HOT 6
- Exception thrown when log arguments have same name, but different separators HOT 2
- Timbre crashing Cider workflow (?) HOT 9
- Using TAOENSSO_TIMBRE_CONFIG_EDN environment variable leads to an execption HOT 4
- Need some help/advice: No debug or info level logging, and duplicated message content HOT 10
- Add console appender opt to control `:raw-console?` HOT 1
- Link to Portal Timbre guide HOT 1
- Latest release uses older com.taoensso/encore; order-dependent if used with e.g. Tufte HOT 2
- API docs link from README results in 404 HOT 3
- Graal optimizations may break uberjar running HOT 6
- Seeing a lot of deprecation warnings in our log HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timbre.