From eed32b752bd82e5ab183285b64939c4a7136cf78 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 24 Apr 2026 00:34:37 +0900 Subject: [PATCH] gha: add hosts file workaround for Windows localhost resolution GitHub Actions Windows Server 2022/2025 runner images ship with the localhost entries commented out in C:\Windows\System32\drivers\etc\hosts and rely on the DNS Client service's built-in rule. That path is subject to Microsoft KB4057932 (getaddrinfo fails with WSAHOST_NOT_FOUND after an AF_INET6 negative cache), which makes Addrinfo.getaddrinfo("localhost", 53, AF_INET, ...) in mrbgems/mruby-socket/test/addrinfo.rb flaky on CI. Prepend explicit 127.0.0.1/::1 localhost entries to the hosts file on all three Windows CI jobs (two mingw-gcc matrix entries and Windows-VC) before running the build, so the resolver avoids the DNS negative cache path and returns the expected IPv4 address. Co-authored-by: Claude --- .github/workflows/build.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9f186358..74ba156bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,12 @@ jobs: run: ruby -v - name: Compiler version run: ${{ env.CC }} --version + - name: Ensure localhost resolves on Windows + if: runner.os == 'Windows' + shell: pwsh + run: | + Add-Content -Path $env:WINDIR\System32\drivers\etc\hosts -Value "127.0.0.1 localhost" + Add-Content -Path $env:WINDIR\System32\drivers\etc\hosts -Value "::1 localhost" - name: Build and test run: rake -m test:run:serial @@ -79,6 +85,11 @@ jobs: persist-credentials: false - name: Ruby version run: ruby -v + - name: Ensure localhost resolves + shell: pwsh + run: | + Add-Content -Path $env:WINDIR\System32\drivers\etc\hosts -Value "127.0.0.1 localhost" + Add-Content -Path $env:WINDIR\System32\drivers\etc\hosts -Value "::1 localhost" - name: Build and test shell: cmd run: |