Skip to content

@remotion/studio: Use server.listen() for port availability checks#6939

Merged
JonnyBurger merged 2 commits intomainfrom
fix/port-selection-listen
Mar 31, 2026
Merged

@remotion/studio: Use server.listen() for port availability checks#6939
JonnyBurger merged 2 commits intomainfrom
fix/port-selection-listen

Conversation

@JonnyBurger
Copy link
Copy Markdown
Member

Summary

  • Switch back from socket.connect() to server.listen() for port availability detection
  • Fixes Remotion Studio failing to start on WSL2 with "No available ports found"

History

The original implementation used server.listen() to check port availability — the most direct way to test if a port is bindable.

In v3.0.13 (000d42195b), this was changed to socket.connect() to fix a port selection issue (#1023). The renderer was synced to match in v3.0.18 (fe00816c25).

However, the connect()-based approach has a fundamental flaw on WSL2: Windows' port forwarding proxy accepts TCP connections on 127.0.0.1 and 0.0.0.0 across a large port range (~1024–41000), even when nothing inside WSL is actually listening. This makes every port in the 3000–3100 scan range appear "occupied", so the studio HTTP server never starts.

server.listen() is the correct fix because it directly tests bindability rather than inferring availability from a failed connection attempt.

Context

  • Original bug report about WSL2: #4315
  • The issue that prompted the original switch to connect(): #1023 — this turned out to be a timeout handling bug in the connect()-based code itself, not a problem with the listen() approach

Test plan

  • Test studio starts correctly on macOS/Linux
  • Test studio starts correctly on WSL2
  • Test that if port 3000 is already in use, the next available port is selected

Closes #4315

🤖 Generated with Claude Code

Switch back to using `server.listen()` instead of `socket.connect()`
to determine if a port is available. This directly tests whether a port
is bindable, rather than inferring availability from a failed connection.

The original implementation used `server.listen()`, but it was switched
to `socket.connect()` in v3.0.13 (000d421) to fix a port selection
issue (#1023). However, the `connect()`-based approach breaks on WSL2,
where Windows' port forwarding proxy accepts TCP connections on
127.0.0.1 and 0.0.0.0 across a large port range (~1024–41000) even
when nothing inside WSL is listening. This causes every port in the
3000–3100 scan range to appear occupied, and the studio fails to start
with "No available ports found".

Closes #4315

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog bot commented Mar 31, 2026

Reviewed PR #6939 — approved. The switch from socket.connect() to server.listen() is the correct fix for WSL2 port detection. No actionable issues found.

Task list (4/4 completed)
  • Review the diff: socket.connect() → server.listen() change
  • Read full file and understand context (callers, port config, tests)
  • Analyze correctness: TOCTOU race, error handling, edge cases
  • Submit review or report no issues

Pullfrog  | View workflow run | Triggered by Pullfrog | Using Big Pickle (free) | 𝕏

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
bugs Ready Ready Preview, Comment Mar 31, 2026 9:53am
remotion Ready Ready Preview, Comment Mar 31, 2026 9:53am

Request Review

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-motivated change. server.listen() is the correct primitive for testing port bindability — it avoids the WSL2 port-forwarding false positives inherent to socket.connect(). Error handling is solid, and server.unref() is a nice defensive touch.

Pullfrog  | View workflow run | Using Big Pickle (free) | 𝕏

With server.listen(), binding a port on one host (e.g. ::) can claim
it on all interfaces, causing parallel listen() attempts on other hosts
to fail with EADDRINUSE. Test hosts sequentially so each server is
closed before the next one tries to bind.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JonnyBurger JonnyBurger changed the title Use server.listen() for port availability checks @remotion/studio: Use server.listen() for port availability checks Mar 31, 2026
@JonnyBurger JonnyBurger merged commit 50891b1 into main Mar 31, 2026
18 checks passed
@JonnyBurger JonnyBurger deleted the fix/port-selection-listen branch March 31, 2026 11:22
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.

npm start error: No available ports found on windows wsl

1 participant