clojure

lvh 2026-01-21T03:36:51.185409Z

io-prepl not flushing over Unix domain sockets (NIO)? 🧵

lvh 2026-01-21T03:37:36.973309Z

I'm building a persistent JVM server that accepts prepl connections over Unix domain sockets (to avoid JVM startup costs). Using Java 21's UnixDomainSocketAddress with NIO channels. Setup:

(let [client (.accept server-channel)  ; ServerSocketChannel/UNIX
        reader (LineNumberingPushbackReader.
                 (InputStreamReader. (Channels/newInputStream client)))
        writer (OutputStreamWriter. (Channels/newOutputStream client))]
    (clojure.core.server/io-prepl :in reader :out writer))
Behavior: Client sends (+ 1 2), server blocks indefinitely. No response sent until client disconnects (triggering EOF). At that point the response finally arrives. What works fine: • TCP prepl via -Dclojure.server.foo='{:port 5555 :accept clojure.core.server/io-prepl}' - instant response • Writing to the same writer directly before io-prepl - flushes fine Workaround: Reimplemented prepl with explicit (.flush writer) after each prn - works perfectly. Theory: io-prepl uses flush-on-newline true but something about NIO channel-derived streams doesn't honor this the same way TCP socket streams do? Has anyone used io-prepl with Unix domain sockets successfully? Am I missing something obvious about how to set up the streams? Clojure 1.12, Java 21, macOS

2026-01-21T04:02:11.740169Z

(oh, I guess not)

2026-01-21T04:10:29.596879Z

https://gist.github.com/hiredman/0885c58b55b674770c277f6dab2eac73 is something I've used in the past with the normal repl, I thing mostly the same, maybe with just an extra buffered output stream because of the call to writer

2026-01-21T04:18:41.500959Z

https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/server.clj#L275 I must be blind, doesn't look like it takes :in or :out

Alex Miller (Clojure team) 2026-01-21T04:38:52.679219Z

We have a ticket related to flushing I think, I know we worked on it for 1.12 but I don't remember if we finished it or not.

Alex Miller (Clojure team) 2026-01-21T04:42:13.408599Z

Oh, I'm remembering this https://clojure.atlassian.net/browse/CLJ-2645