Skip to content

fix(fastify): listen on a socket path - #18053

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
johnnyhuirilef:fix/fastify-listen-socket-path
Oct 9, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
johnnyhuirilef:fix/fastify-listen-socket-path

Conversation

@johnnyhuirilef

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Issue Number: #18052

Closes #18052

Hi! 👋 On the Fastify adapter, app.listen('/path/to.sock') crashes the process with a RangeError about a NaN port. The same call works on the Express adapter.

FastifyAdapter.listen() turns every argument that is not an object into { port: +value }. A path is not a number, so the port becomes NaN. This came with 522b991 in Nest 9. Before it, a socket path worked.

I ran the repro on 12.1.2:

RESULT: BUG: 1 of 4 cases did not listen (a socket path crashes the process on Fastify).

What is the new behavior?

A string that is not a number now becomes { path }. Numbers and numeric strings still become { port }, and the object form does not change. The adapter does not pass a host with a path, because a host does not apply to a socket.

The same repro against a local build of this branch:

RESULT: FIXED: all 4 cases listen and answer HTTP 200.

Does this PR introduce a breaking change?

  • Yes
  • No

Only a non-numeric string changes, and it crashed the process before.

Other information

The specs cover these cases:

  • Unit: a socket path, a string that starts with a number, a named pipe, a path with a host and a path with a callback.
  • Unit: a numeric string, a number and the object form keep their old behavior.
  • Integration: a real Fastify app listens on a socket path, with and without a host, and answers a request over it. getUrl() returns the http+unix:// form.

One thing I left as is. When listen() gets an options object and a host, the adapter writes the host into the caller's object. I am happy to look at it in a follow-up if you think it is worth it. 🙂

app.listen('/path/to.sock') crashed the process on the Fastify adapter.
Node threw a RangeError about a NaN port on a later tick. A try/catch
cannot catch it, and the message did not mention the socket path.

The cause is 522b991. It changed listen to pass { port: +port } for
the port argument. A path is not a number, so the port was NaN. Express
still listened on the same argument.

Now a string that is not a number becomes { path }. Numbers and numeric
strings still become { port }. The adapter sets no host for a path,
because the host does not apply to a socket. The object form is
unchanged.

Closes nestjs#18052
fengdi721 added a commit to fengdi721/nest that referenced this pull request Oct 8, 2026
Review nestjs#18053 locally (ci, mergeability, own repro test,
mutation testing, edge cases versus node net.listen) and draft a
review comment. Rehearse the full pr flow with a contributing.md fix
opened against the fork. Add practices P26-P30 and a journal entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamilmysliwiec
kamilmysliwiec merged commit b647b57 into nestjs:master Oct 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fastify adapter crashes when listen() gets a Unix socket path

2 participants