nREPL server never answers a request with non-ASCII text that arrives in more than one chunk
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, networking
Research direction
Start in src/nbb/impl/nrepl_server.cljs at on-connect, where pending is joined with incoming TCP data, then read nbb.impl.bencode/decode to understand how request lengths are parsed. Keep the pending data byte-based across chunks as the issue describes. Confirm completion by sending the two-write reproduction with non-ASCII text and checking that it returns the expected value and the socket can handle later requests.
Written by the indexing model from the issue text.
Description
version
nbb 1.3.204. The same code is on main at v1.6.215.
platform
macOS 26.7.3, Node.js v26.14.0
problem
nbb's nREPL server never answers a request that holds a multi-byte character when the request arrives in two or more TCP chunks. After that, it answers nothing else on that socket either. A new connection works.
on-connect in src/nbb/impl/nrepl_server.cljs keeps the unparsed tail in pending and joins it with the next chunk via (str p data). That turns the bytes into a JS string. nbb.impl.bencode/decode then slices each netstring by UTF-16 units, while the length prefix counts bytes. The request never parses and stays in pending, and every later request on the socket queues behind it.
A client that writes bencode token by token hits this on every request with non-ASCII text. One example is bencode.core's write-bencode on a socket output stream. Requests over 64 KB arrive in several chunks whatever the client does.
repro
Start nbb nrepl-server :port 1667, then run this with bb:
(require '[bencode.core :as b])
(import '[java.net Socket] '[java.io ByteArrayOutputStream PushbackInputStream])
(defn eval-in-two-writes [code]
(let [bo (ByteArrayOutputStream.)
_ (b/write-bencode bo {"op" "eval" "code" code "id" "1"})
bs (.toByteArray bo)]
(with-open [s (doto (Socket. "localhost" 1667) (.setSoTimeout 3000))]
(let [out (.getOutputStream s)]
(.write out bs 0 1)
(.flush out)
(Thread/sleep 100)
(.write out bs 1 (dec (alength bs)))
(.flush out)
(try (String. ^bytes (get (b/read-bencode (PushbackInputStream. (.getInputStream s))) "value") "UTF-8")
(catch java.net.SocketTimeoutException _ "no answer in 3 s"))))))
(println "(str \"abc\") ->" (eval-in-two-writes "(str \"abc\")"))
(println "(str \"a·b\") ->" (eval-in-two-writes "(str \"a·b\")"))
Output:
(str "abc") -> "abc"
(str "a·b") -> no answer in 3 s
expected behavior
Both requests get their value: (str "a·b") -> "a·b".
Keeping pending as a Buffer and joining with (js/Buffer.concat #js [p data]) should fix it. decode already handles Buffers: the same request sent in one write gets its answer.
- Dominant language
- Clojure
- Stars
- 972
- Forks
- 56
- Avg merge
- 1m
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from babashka/nbb
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 1/5 Under an hour Newbie friendliness 55/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
nextjournal/clerk#830 ·
-
IOP tokens release blocker team qa team qa autotests WG adoption
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
penpot/penpot#13540 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
izhangzhihao/intellij-rainbow-brackets#2903 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Data Studio semantic layer: clicking a table or metric row only opens it when you click the namePossibly taken @sanketpatel32 claimed this 1 day ago. Open.Needs Triage .Team/UXWest Priority:P3 Type:Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
metabase/metabase#88853 · 1 comment ·
Maintainers usually reply within 1 day