microsoft / WSL

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

Asterisk glob expansion (*) unexpected behaviour in bash on WSL's 9P mounts #12227

Open daubmannus opened 12 hours ago

daubmannus commented 12 hours ago

Windows Version

Microsoft Windows [Version 10.0.19045.5011]

WSL Version

2.3.24.0

Are you using WSL 1 or WSL 2?

Kernel Version

5.15.153.1-2

Distro Version

Ubuntu 22.04.5

Other Software

No response

Repro Steps

The behavior described in the report is observed only on WSL's 9P mounts of Windows disks.

sudo mkdir -p /mnt/c/test cd /mnt/c/test touch 1 2

run the script

#!/bin/bash

# save true file number
true_f_num=$(for fn in *; do echo; done | wc -l)

while :; do
    # count of iterations to outer loop pipe
    echo

    # save current file list in file
    echo -n '' >.list

    for fn in *; do
        echo "$fn" >>.list

    # line below causes unexpected behaviour
    # on 9P mounts (like /mnt/c/...)
    # (WSL2, ubuntu 22.04)
    done | cat > .tmp; rm .tmp

    # check 
    [ $(cat .list | wc -l ) -ne $true_f_num ] && break

done | wc -l

output: some random number

cat .list

output:

1
2
2

The appearance of duplicate lines in .list indicates that at least one of the previous two expectations is violated. This would be a bug.

see the discussion here: https://stackoverflow.com/a/79146114/10244657

Expected Behavior

Script runs forever. File .list is populated with an exact list of files on each iteration of the loop.

Actual Behavior

On WSL's 9P mounts of Windows' disks script stops after some random number of iterations, outputs this number. File .list contains the name of one of the files in the current directory twice.

Diagnostic Logs

WslLogs-2024-11-01_06-25-00.zip

github-actions[bot] commented 12 hours 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'.
github-actions[bot] commented 12 hours ago
Diagnostic information ``` Issue was edited and new log file was found: https://github.com/user-attachments/files/17595981/WslLogs-2024-11-01_06-25-00.zip Detected appx version: 2.3.24.0 ```