Welcome! Please see the About page for a little more info on how this works.

0 votes
in REPL by

The following code is used in {{src/clj/clojure/core/server.clj}} to validate whether a port number is valid:

(defn- validate-opts "Validate server config options" [{:keys [name port accept] :as opts}] (doseq [prop [:name :port :accept]] (required opts prop)) (when (or (not (integer? port)) (not (< -1 port 65535))) (throw (ex-info (str "Invalid socket server port: " port) opts))))

However this is very slightly incorrect, since port 65535 is excluded but it is actually a valid port.

`
user=> (defn is-invalid-port [port] (or (not (integer? port)) (not (< -1 port 65535))))

'user/is-invalid-port

user=> (is-invalid-port 65534)
false
user=> (is-invalid-port 65535) ; should be false!
true
user=> (is-invalid-port 65536)
true
`

This is corroborated by (link: https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html#ServerSocket(int) text: {{ServerSocket}}'s Javadoc):

{quote}
IllegalArgumentException - if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
{quote}

Patch: port-65535-obo-v2.patch

Prescreened: Alex Miller

3 Answers

0 votes
by

Comment made by: alexmiller

Hi Keyhan, have you signed the Clojure Contributor Agreement? https://clojure.org/community/contributing. If not, please do so.

Another, maybe better, solution here is (<= 0 port 65535) - that reads more closely to the check.

0 votes
by

Comment made by: kvakil

Yes, just earlier today.

I agree that looks better. Current patch is {{port-65535-obo-v2.patch}}.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2387 (reported by kvakil)
...