Skip to content

Fix CreateInstance failure when Windows hosts file exceeds message size cap#40718

Merged
benhillis merged 1 commit into
masterfrom
benhill/fix-large-hosts-message
Jun 5, 2026
Merged

Fix CreateInstance failure when Windows hosts file exceeds message size cap#40718
benhillis merged 1 commit into
masterfrom
benhill/fix-large-hosts-message

Conversation

@benhillis
Copy link
Copy Markdown
Member

@benhillis benhillis commented Jun 5, 2026

Summary

On Windows 10 where DNS tunneling is unavailable, the Windows hosts file content is embedded in the configuration message sent to the guest init. If the parsed hosts file exceeds 4MB (e.g. ad-blocker hosts lists), the guest rejects it with the message size safety check added in 2.7.x, causing Wsl/Service/CreateInstance/E_UNEXPECTED.

Changes

  • Skip oversized hosts file: If the parsed hosts content exceeds 1MB, return empty and emit a user warning instead of embedding it in the message
  • Bump message size cap: Increase the receive-side safety cap from 4MB to 16MB (in both socketshared.h shared path and HandleIO.cpp Windows path) as additional headroom

Why this only affects Win10

On Win11, DNS tunneling is enabled by default so the hosts file is never embedded in the config message. On Win10 19044, the DNS tunneling APIs don't exist (ERROR_PROC_NOT_FOUND), so the code falls back to embedding the full hosts file.

Validation

  • Built successfully
  • The fix is a graceful degradation: users with oversized hosts files get a warning and lose host file reflection in WSL, but the distro starts successfully

Fixes #40696
Fixes #40700
Fixes #40699

@benhillis benhillis requested a review from a team as a code owner June 5, 2026 19:17
Copilot AI review requested due to automatic review settings June 5, 2026 19:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses WSL CreateInstance failures on Windows 10 when DNS tunneling is unavailable and the Windows hosts file content is embedded into the init configuration message. It avoids sending oversized hosts content and increases the socket receive-side message size cap to reduce unexpected failures.

Changes:

  • Skip embedding the Windows hosts file content when the parsed payload exceeds 1 MiB, emitting a user warning instead.
  • Increase the socket message size safety cap from 4 MiB to 16 MiB in both the shared and Windows receive paths.
  • Add a new localized user-warning string describing the oversized-hosts behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/windows/common/HandleIO.cpp Raises the Windows socket receive message-size limit to 16 MiB.
src/windows/common/filesystem.cpp Adds a 1 MiB guard for parsed Windows hosts content and emits a user warning when exceeded.
src/shared/inc/socketshared.h Raises the shared receive message-size limit to 16 MiB for host/guest communication.
localization/strings/en-US/Resources.resw Introduces a new user-facing warning message about oversized hosts files.

Comment thread src/windows/common/filesystem.cpp Outdated
Comment thread src/windows/common/filesystem.cpp Outdated
Comment thread localization/strings/en-US/Resources.resw Outdated
@benhillis benhillis force-pushed the benhill/fix-large-hosts-message branch from 8604539 to 4e0b744 Compare June 5, 2026 20:01
Copilot AI review requested due to automatic review settings June 5, 2026 20:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/shared/inc/socketshared.h:74

  • The protocol max message size (16 MiB) is now hard-coded here and separately in src/windows/common/HandleIO.cpp. Since both are enforcing the same safety cap for the same message header field, keeping the limit as a shared constant would reduce the risk of future drift (e.g., one side updated but not the other).
    if (MessageSize > 16 * 1024 * 1024) // 16 MiB
    {
#if defined(_MSC_VER)
        THROW_HR_MSG(E_UNEXPECTED, "Message size too large: %llu", MessageSize);
#elif defined(__GNUC__)
        THROW_UNEXPECTED();
#endif
    }

Comment thread src/windows/common/filesystem.cpp Outdated
OneBlue
OneBlue previously approved these changes Jun 5, 2026
@benhillis benhillis force-pushed the benhill/fix-large-hosts-message branch from 6d7d053 to 311f7c3 Compare June 5, 2026 20:14
…ze cap

On Windows 10 where DNS tunneling is unavailable, the hosts file content
is embedded in the configuration message sent to the guest init. If the
hosts file exceeds the message size safety check (added in 2.7.x), the
guest rejects it causing E_UNEXPECTED.

Fix by:
- Skipping the hosts file content if it exceeds 8MB, with a user warning
- Bumping the message size cap from 4MB to 16MB as additional headroom

Fixes #40696
Fixes #40700
Fixes #40699

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the benhill/fix-large-hosts-message branch from 311f7c3 to 8eb1de1 Compare June 5, 2026 20:15
@benhillis benhillis enabled auto-merge (squash) June 5, 2026 20:45
@benhillis benhillis merged commit 9ab38e9 into master Jun 5, 2026
11 checks passed
@benhillis benhillis deleted the benhill/fix-large-hosts-message branch June 5, 2026 22:05
benhillis added a commit that referenced this pull request Jun 6, 2026
…ze cap (#40718) (#40726)

On Windows 10 where DNS tunneling is unavailable, the hosts file content
is embedded in the configuration message sent to the guest init. If the
hosts file exceeds the message size safety check (added in 2.7.x), the
guest rejects it causing E_UNEXPECTED.

Fix by:
- Skipping the hosts file content if it exceeds 8MB, with a user warning
- Bumping the message size cap from 4MB to 16MB as additional headroom

Fixes #40696
Fixes #40700
Fixes #40699

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants