Fork me on GitHub
#babashka
<
2024-07-01
>
borkdude08:07:27

Welcome 1700th member of this channel!

🙌 6
🎉 5
clojure 5
👍 3
babashka 4
1
1
folcon10:07:56

Anyone else experiencing this on osx when trying to CTRL-c?

Exception in thread "SIGINT handler" java.lang.UnsupportedOperationException: Method not implemented: handle
        at babashka.impl.proxy$method_or_bust.invokeStatic(proxy.clj:8)
        at babashka.impl.proxy$proxy_fn$fn__21284.invoke(proxy.clj:78)
        at babashka.impl.proxy.proxy$java.lang.Object$SignalHandler$d8c00ec7.handle(Unknown Source)
        at sun.misc.Signal$InternalMiscHandler.handle(Signal.java:198)
        at jdk.internal.misc.Signal$1.run(Signal.java:220)
        at java.lang.Thread.run(Thread.java:829)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
I've been CTRL-z and then killing the process manually as a workaround =)...

borkdude10:07:22

Please provide a complete sequence of steps to reproduce this

folcon10:07:22

Give me a moment, trying to produce a minimal example 😃

folcon10:07:48

Ok, this is plugging into a lot of bb's internals, I suppose my question is, there's signal handlers defined for INT and TERM:

(defmacro set-signal-handler!
  [signal f]
  `(sun.misc.Signal/handle
    (sun.misc.Signal. ~signal)
    (proxy [sun.misc.SignalHandler] []
      (handle [signal#] (~f signal#)))))

(set-signal-handler! "INT" cleanup)
(set-signal-handler! "TERM" cleanup)
The error is saying there's no SIGINT handler, I tried adding a SIGINT entry, but I'm getting:
(set-signal-handler! "SIGINT" cleanup)
    ^--- Unknown signal: SIGINT
So I'm assuming that INT is supposed to be SIGINT... So I'm trying to work out why registering (set-signal-handler! "INT" cleanup) is not calling this handler? I should be able to debug from there 😃... If this isn't obvious, that's fine, I'll have to dig into the codebase and work out what's going on 😃... (which may be what's required, I'm a bit unfamilar with babashka, so was just seeing if there's any obvious starting points as this seems to be something internal)

borkdude10:07:02

Is that macro something from yourself or something from bb?

borkdude10:07:22

You're not providing a complete standalone step by step repro. E.g. it is unknown what cleanup does. You haven't said: run this script and then hit ctrl-c or whatever. Having said that, this works for me (bb newest):

(defmacro set-signal-handler!
  [signal f]
  `(sun.misc.Signal/handle
    (sun.misc.Signal. ~signal)
    (proxy [sun.misc.SignalHandler] []
      (handle [signal#] (~f signal#)))))

(defn cleanup [_]
  (prn :dude))

(set-signal-handler! "INT" cleanup)
(set-signal-handler! "TERM" cleanup)

@(promise)
The @(promise) prevents the script from exiting. A step by step repro with full context helps sorting out the issue. Any questions/assumptions can be based on that, after the issue is clear

folcon10:07:45

Thanks @U04V15CAJ, in which case, let me dig into the source here and see if I can figure out the issue or I figure out a minimal case!

borkdude11:07:18

I mean a repro from a user perspective, not a solution to a problem

M3tti12:07:22

If i have an httpkit application in babashka how do i make it run? cause currently when defining a -main function the process just dies 😕 and i have no clue

(defn -main []
  (hk-server/run-server (wrap-params (wrap-session (wrap-anti-forgery #(ruuter/route (routes) %)))) {:port 8080}))
If i start this with bb -m my-app.core or define a task that triggers tha -main function it imidiatly closes

borkdude12:07:21

you need to block, since run-server isn't blocking. e.g. add @(promise) to the end of the -main function

M3tti13:07:14

aaaaaaaah -.- i'm to dumb -.-

borkdude13:07:57

it's a very common source of confusion, don't worry ;)

frozenlock18:07:40

Will my code be usable in babashka if it uses things like java.security.MessageDigest and java.util.Base64? Is everything from java available?

borkdude18:07:02

Not everything but those are available

frozenlock18:07:30

Nice! I glanced at the readme (and saw usage of java.time) but couldn't find a list. Is it written somewhere?

borkdude18:07:44

You can see the entire list with this command:

bb -e '(babashka.classes/all-classes)'

frozenlock18:07:21

Amazing, thank you very much!

borkdude18:07:36

👍 If something important is missing, let me know, we can always check if it makes sense to add

👍 2