microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.51k stars 823 forks source link

Querying `${hostname}.local` takes forever due to DNS server that is built into WSL #12080

Open sigasigasiga opened 1 month ago

sigasigasiga commented 1 month ago

Windows Version

Microsoft Windows [Version 10.0.22631.4169]

WSL Version

2.2.4.0

Are you using WSL 1 or WSL 2?

Kernel Version

Linux version 5.15.153.1-microsoft-standard-WSL2

Distro Version

Any, I guess. The bug reproduces on Ubuntu 23.04 and on openSUSE Tumbleweed 20240923

Other Software

on my openSUSE Tumbleweed machine: avahi-daemon 0.8 libnss-mdns 0.15.1-1.5 systemd 256.5-1.1

Repro Steps

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 10.255.255.254

$ time getent hosts ${hostname}.local
172.28.0.1      egor-bychin-pc.local

________________________________________________________
Executed in   10.02 secs      fish           external
   usr time    3.26 millis  177.00 micros    3.08 millis
   sys time    0.53 millis  530.00 micros    0.00 millis

However, if I change my DNS server in /etc/resolv.conf, then everything is super fast:

$ cat /etc/resolv.conf
nameserver 1.1.1.1

$ time getent hosts ${hostname}.local
172.28.0.1      egor-bychin-pc.local

________________________________________________________
Executed in   10.55 millis    fish           external
   usr time    1.31 millis   57.00 micros    1.26 millis
   sys time    0.21 millis  210.00 micros    0.00 millis

Expected Behavior

I get the results in 10 seconds

Actual Behavior

I get the results in 0.00001 seconds

Diagnostic Logs

No response

github-actions[bot] commented 1 month ago

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs Download and execute [collect-wsl-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-wsl-logs.ps1) in an **administrative powershell prompt**: ``` Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1 Set-ExecutionPolicy Bypass -Scope Process -Force .\collect-wsl-logs.ps1 ``` The script will output the path of the log file once done. If this is a networking issue, please use [collect-networking-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-networking-logs.ps1), following the instructions [here](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#collect-wsl-logs-for-networking-issues) Once completed please upload the output files to this Github issue. [Click here for more info on logging](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#8-collect-wsl-logs-recommended-method) If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

sigasigasiga commented 1 month ago

WslNetworkingLogs-2024-09-26_00-58-02.zip WslLogs-2024-09-26_00-56-16.zip

logs

github-actions[bot] commented 1 month ago
Diagnostic information ``` Multiple log files found, using: https://github.com/user-attachments/files/17138533/WslNetworkingLogs-2024-09-26_00-58-02.zip Detected appx version: 2.2.4.0 optional-components.txt not found ```
CatalinFetoiu commented 1 month ago

hello. thanks for reporting the issue. can you please try either of the following 2 solutions documented at https://learn.microsoft.com/en-us/windows/wsl/troubleshooting#resolve-local-names-in-wsl and let us know if those resolve the issue?

1) keep using networkingMode=nat (as you are currently doing), but disable dnsTunneling 2) use networkingMode=mirrored and do the additional configs from the link above - install libnss-mdns and configure /etc/nsswitch.conf (I see you already have libnss-mdns installed)

sigasigasiga commented 1 month ago

@CatalinFetoiu thank you for your reply!

Setting networkingMode=mirrored didn't help at all.

However, by setting dnsTunneling=false I managed to get some huge boost -- now it takes whopping 1 second to complete my request!

But I must admit that 1 second is still quite slow comparing to the results I'm getting with using any custom DNS server (e.g. 1.1.1.1):

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.28.0.1

$ time getent hosts ${hostname}.local
172.28.0.1      egor-bychin-pc.local

________________________________________________________
Executed in    1.05 secs      fish           external
   usr time    2.32 millis    0.00 micros    2.32 millis
   sys time    0.43 millis  435.00 micros    0.00 millis
$ cat /etc/resolv.conf
nameserver 1.1.1.1

$ time getent hosts ${hostname}.local
172.28.0.1      egor-bychin-pc.local

________________________________________________________
Executed in  116.05 millis    fish           external
   usr time    1.95 millis   89.00 micros    1.86 millis
   sys time    0.35 millis  355.00 micros    0.00 millis

I think the results may still be greatly improved by some changes on your side

CatalinFetoiu commented 1 month ago

@sigasigasiga thanks for following up regarding networkingMode=mirrored, sorry, I forgot to mention you need to be on a build 2.3.17 for this to work (we made some fixes so that mDNS can work in mirrored mode). Also, you don't need to disable dnsTunneling in this case (disabling it is needed only in NAT mode)

for the case where you see a 1 second delay, could you please collect new networking logs (WslNetworkingLogs) ?

sigasigasiga commented 1 month ago

@CatalinFetoiu


regarding networkingMode=mirrored, sorry, I forgot to mention you need to be on a build 2.3.17 for this to work (we made some fixes so that mDNS can work in mirrored mode).

I actually have a newer version of WSL

> wsl --version
WSL version: 2.3.24.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.22631.4169

And the domain still resolves in 10 seconds with networkingMode=mirrored. Did you mean that I need to downgrade it to 2.3.17 for mirrored networking mode to fix the problem?


Also, you don't need to disable dnsTunneling in this case (disabling it is needed only in NAT mode)

Yes, I got that right from the start: I've done the first test with

[wsl2]
networkingMode=mirrored
#dnsTunneling=false

and the second one with

[wsl2]
#networkingMode=mirrored
dnsTunneling=false

for the case where you see a 1 second delay, could you please collect new networking logs (WslNetworkingLogs) ?

Okay, here's the logs collected from the machine with dnsTunneling=false set in .wslconfig. As in previous tests, the command I ran was getent hosts ${hostname}.local.

WslNetworkingLogs-2024-10-07_16-52-49.zip

github-actions[bot] commented 1 month ago
Diagnostic information ``` .wslconfig found Detected appx version: 2.3.24.0 optional-components.txt not found ```
CatalinFetoiu commented 1 month ago

@sigasigasiga thanks for sending logs

sorry for the confusion about the WSL build number, I meant to say any build that is 2.3.17 or higher

could you please also collect networkings logs from the mirrored networking case? We should understand why resolution takes 10 seconds there

sigasigasiga commented 1 month ago

@CatalinFetoiu WslNetworkingLogs-2024-10-12_03-45-01.zip

github-actions[bot] commented 1 month ago
Diagnostic information ``` .wslconfig found Detected appx version: 2.3.24.0 optional-components.txt not found ```