Fork me on GitHub
#hyperfiddle
<
2023-08-06
>
braai engineer08:08:20

What's the newest JDK version I can build Electric with safely via Docker? Any benefits to newer versions, e.g. performance? Starter app Dockerfile uses OpenJDK 11 and runs with Amazon Corretto 11: https://github.com/hyperfiddle/electric-starter-app/blob/main/Dockerfile

braai engineer08:08:55

Electric app runs locally via REPL & builds via Docker but when I try to build uberjar on host or via Docker, I get this exception about a Protocol:

Exception in thread "main" java.lang.NoClassDefFoundError: myproject/proto/AMyProto
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1022)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
...
Caused by: java.lang.ClassNotFoundException: myproject.proto.AMyProto
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
        ... 114 more
prod.clj has (:gen-class) another gen-class issue? AOT?
;; proto:
(defprotocol AMyProto
  (do-thing [this ...])
  ...)

;; mock file:
(ns mymock
  (:require [myproject.proto :as proto]))

(defrecord MyImpl [!history secret-token] ;; access token?
  proto/AMyProto
  (do-thing [this ...] ...))
Hmm, any ideas? Could it be JDK version issue?

braai engineer08:08:53

Tried adding (:gen-class) to myproject.proto namespace, but no luck.

braai engineer08:08:34

also happens on host machine that's running Java Oracle 20.0.01

braai engineer08:08:45

Requiring myproject.proto NS from prod.clj does not help

Dustin Getz12:08:45

this is not an electric issue

Dustin Getz12:08:48

did you resolve it?

braai engineer12:08:07

No 😕 Temporary workaround by deploying dev build to prod

Dustin Getz12:08:21

this is likely the root problem causing the rest of your problems

braai engineer12:08:22

my pain is no logs

braai engineer12:08:32

just reactorfailure

Dustin Getz12:08:02

logs are not broken, please check out a clean starter app and convince yourself they work

Dustin Getz12:08:12

you can add more logs to your app's boot sequence

braai engineer12:08:19

I compared mine to the starter-app and seems to be same

Dustin Getz12:08:20

you can also turn log level up to trace

braai engineer12:08:25

ok will try that

braai engineer12:08:39

maybe I need to catch exception in jetty side

Dustin Getz12:08:58

i want to be clear: if logs are broken, it is your fault

braai engineer12:08:20

sure, but I've had logging issues before so I'd rather mention it than be stuck for hours

Dustin Getz12:08:53

Electric Does Not Have Logging Issues, if you suspect otherwise please checkout a clean starter app and confirm that it is true, and save yourself the hours of pain debugging something that is not broken

braai engineer12:08:59

ok - just trying to get things working 🙂

braai engineer08:08:20

How should I prevent deployment if RCF tests fail? Does someone have a Github Actions or Dokku template lying around?

braai engineer09:08:49

ReactorFailure on prod uberjar build, but works fine in REPL build. No errors in server logs - only client.

Connecting...
main.9BFB58C0E5DF4F15F4C87A7ED5236453.js:1522 Connected.
main.9BFB58C0E5DF4F15F4C87A7ED5236453.js:1419 WebSocket is already in CLOSING or CLOSED state.
Reactor failure:

"Remote error - 1011 org.eclipse.jetty.websocket.core.exception.WebSocketException:
Error: Remote error - 1011 org.eclipse.jetty.websocket.core.exception.WebSocketException: WebSocketAdapter$WebSocketPingPongListener$12d400b6 OPEN met
    at new Tm ()
    at Wm ()
    at Vm ()
    at p ()
    at Function.t [as o] ()
    at lT ()
    at e.resume ()
    at lT ()
    at e.resume ()
    at mU ()"
This is probably a Datomic error due to lack of schema or seed data, but why zero logs on server? Verified it's not Datomic. I am transacting schema and can run queries via an API endpoint. I compared my logback.xml to starter app settings and don't see an issue. plz halp deploy blocked

braai engineer09:08:10

logback.xml:

<!-- Jetty logger config. See  and
ask ChatGPT. `scan` and `scanPeriod` enable hot reload of logger config, leave on! -->
<configuration scan="true" scanPeriod="5 seconds">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%highlight(%-5level) %logger: %msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
    </root>

    <logger name="hyperfiddle" level="DEBUG" additivity="false"><appender-ref ref="STDOUT" /></logger>
    <!-- <logger name="hyperfiddle.electric.impl.io" level="INFO" additivity="false"><appender-ref ref="STDOUT" /></logger> -->
    <logger name="quey" level="DEBUG" additivity="false"><appender-ref ref="STDOUT" /></logger>
</configuration>

braai engineer09:08:53

@U09K620SG I've added an nREPL into my uberjar build. How do I trigger an Electric run from REPL to try and see an error, please? (e/run something)?

braai engineer10:08:50

this doesn't seem to work:

(ns scratch
  (:require [hyperfiddle.electric :as e]
            [hyperfiddle.electric-dom2 :as dom]))

(e/defn Test []
  (dom/div "hi"))

(e/run (Test.))

braai engineer10:08:33

OK this runs "in prod" but obviously fails because DOM stuff missing on server for my components:

(ns scratch
  (:require [hyperfiddle.rcf :as rcf :refer (tests tap %)]
            [hyperfiddle.electric :as e]
            [hyperfiddle.electric-dom2 :as dom]
            [missionary.core :as m]
            [hyperfiddle.history :as history];; for core
            [quey.manage.core :as core]
            [datomic.api :as d]))

(e/defn SanityTest [!x]
  (prn "hi")
  (let [x (e/watch !x)                       ; reactive x
        a (inc x)]                           ; reactive a depends on reactive x
    (tap (+ a (inc x)))))
  ;(d/q nil nil))

;(e/run Test)

(tests "Electric baseline program - a dataflow diamond"

  (def dispose (e/run (core/Page. [:thing]))) ;; fails because DOM stuff

  ;; rest is jsut here to test

  (def !x (atom 0))
  (def dispose (e/run (SanityTest. !x)))
  % := 2
  (swap! !x inc)
  % := 4
  (swap! !x inc)
  % := 6
  (dispose))

mattias15:01:36

For me, this error was caused by requiring xtdb.api or anything that requires xtdb.api in user.clj . Similarly, at dev/repl time, this was not an issue, but occurred only with uberjars. Requiring xtdb.api (or anything that requires it) in prod.clj was not a problem. I was able to work around it by avoiding requiring utils/start-xtdb! in user.clj and instead doing (def start-xtdb! (delay @(requiring-resolve 'utils/start-xtdb!))) . It was really hard to track down, had to do a full "binary search" on my code vs the electric-starter-app code. @U09K620SG FYI

braai engineer16:01:28

@U5S5570KH I can’t remember but try moving user.clj footgun to ~/src-dev and adding “src-dev” to :paths for :dev alias.

mattias16:01:52

So that user.clj won't get included in the uberjar build?

braai engineer10:08:04

I had to resort to deploying a dev build because I can't get uberjar working (ReactorFailure - zero server logs). How can I hide the shadow-cljs thingy until I can fix?

joshcho18:08:55

I am trying to get only the first value of a flow. I am currently doing something like this:

(->> (e/fn [] (e/server (:task/toggled (d/entity db task-id))))
     (m/eduction (filter boolean?))
     (m/reductions conj [])
     new
     first)
This feels roundabout, as the rest of the flow still is received, only to be discarded (maybe that's okay). Is there a better way to do this?

Dustin Getz18:08:46

e/snapshot ?

😮 2
Dustin Getz18:08:12

use e/watch to bridge atoms to electric, which you already know, i think you might be over thinking it

❤️ 2
Dustin Getz18:08:12

(e/server (println (e/client (e/watch !x)))) accomplishes your goal of running an effect on the server every time an atom changes

Dustin Getz18:08:09

oops, did you delete a question? or somehow i replied to wrong thread

joshcho18:08:53

Ah, no. I ended up figuring it out! I definitely was overthinking it.

joshcho19:08:03

The incremental compiler model is very powerful, I just need to get more in the habit of thinking that way.