Skip to content

fix: resolve state directory under sudo and detect WSL2 mirrored networking#286

Open
gerardbalaoro wants to merge 2 commits intovercel-labs:mainfrom
gerardbalaoro:fix/wsl2-sudo-state-dir
Open

fix: resolve state directory under sudo and detect WSL2 mirrored networking#286
gerardbalaoro wants to merge 2 commits intovercel-labs:mainfrom
gerardbalaoro:fix/wsl2-sudo-state-dir

Conversation

@gerardbalaoro
Copy link
Copy Markdown
Contributor

@gerardbalaoro gerardbalaoro commented May 5, 2026

Two fixes for Linux/WSL2 environments. Closes #283.

1. State directory under sudo (packages/portless/src/cli-utils.ts)

When portless is run under sudo, os.homedir() returns /root, so the proxy and child processes disagree on where the state directory lives. This patch resolves the original user's home directory via getent passwd $SUDO_USER, falling back to /home/$SUDO_USER.

2. WSL2 mirrored networking warning (packages/portless/src/cli-utils.ts, cli.ts, README.md, skills/portless/SKILL.md)

Detects WSL2 via /proc/version and checks wslinfo --networking-mode to see if mirrored networking is enabled. If not, prints a warning with setup instructions when the proxy starts. Also documents the requirement in the README and SKILL.md.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

@gerardbalaoro is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread packages/portless/src/cli-utils.ts Outdated
Comment thread packages/portless/src/cli-utils.ts
When the proxy starts with sudo, os.homedir() returns /root, so the
proxy used /root/.portless for state. But child apps run as the normal
user and write to /home/<user>/.portless. The proxy never saw route
registrations because they lived in different directories.

Use SUDO_USER + getent passwd to resolve the original user's home
directory so both proxy and apps share the same state directory.

Fixes vercel-labs#283
Detect WSL2 via /proc/version and check mirrored networking status
with wslinfo CLI. Print setup instructions only when WSL2 is detected
and mirrored networking is not configured, so Windows browsers can
reach the proxy via localhost.

Update README and SKILL.md with WSL2 setup documentation.

Refs vercel-labs#283
@gerardbalaoro gerardbalaoro force-pushed the fix/wsl2-sudo-state-dir branch from 223589d to 95e1a0f Compare May 5, 2026 10:31
@slavbar
Copy link
Copy Markdown

slavbar commented May 5, 2026

Hi @gerardbalaoro ,

Thanks for your PR, I've added a comment in the linked issue thread: #283 (comment)

@slavbar
Copy link
Copy Markdown

slavbar commented May 5, 2026

Hi @gerardbalaoro ,

Thanks for your PR, I've added a comment in the linked issue thread: #283 (comment)

Anyway it seems reasonable to merge this PR if it resolves the routing issue, even though it doesn’t address the SSL problem.

Since it now works with NAT, I wonder if the warning is still applicable.

image

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.

Not working in WSL2 – 404 “No app registered” on https://<project>.localhost

2 participants