Skip to content

Accept a port as a number or a string - #4180

Merged
bbatsov merged 2 commits into
masterfrom
normalize-port
Sep 3, 2026
Merged

Accept a port as a number or a string#4180
bbatsov merged 2 commits into
masterfrom
normalize-port

Conversation

@bbatsov

@bbatsov bbatsov commented Aug 28, 2026

Copy link
Copy Markdown
Member

Ports are strings throughout CIDER - cider-select-endpoint insists on it for cider-known-endpoints - but a number is the natural thing to hand to cider-connect from Lisp, and both spellings connect happily today.

What doesn't work is mixing them. The port is stored exactly as it arrived, and session and REPL matching compares it with equal, so:

(cider-connect (list :host "127.0.0.1" :port 51139 :project-dir "..."))
;; stored :port is the integer 51139

and a later lookup with "51139" finds nothing - CIDER offers to start a second session for a connection it already has, and cider--score-repls scores the right REPL lower than it should.

nrepl--normalize-port settles on the string form at the two points a port enters the client, so callers can pass either and they compare equal afterwards.

One test change worth flagging: the restart-session spec compared ports with =, which only worked because they happened to be numbers on that path. It uses equal now, like the code it exercises. That spec failing was also what surfaced this - it left a half-connected session behind and took three unrelated specs down with it.

Ports are strings throughout CIDER - cider-select-endpoint insists on it
for cider-known-endpoints - but a number is the natural thing to hand to
cider-connect from Lisp, and both spellings connect happily. What didn't
work was mixing them: the port is stored as it arrived, and the session
and REPL matching compares it with equal, so connecting with 51139 and
later looking for "51139" found nothing and offered to start a second
session for a connection already open.

nrepl--normalize-port settles on the string form at the two places a port
enters the client, so callers can pass either.

The restart-session spec compared ports with = and so quietly depended on
them being numbers there; it uses equal now, like the code it exercises.
@bbatsov
bbatsov merged commit d0dbbcc into master Sep 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant