git-for-windows / git

A fork of Git containing Windows-specific patches.
http://gitforwindows.org/
Other
8.18k stars 2.49k forks source link

bash redirect "magic" variable content to input of command hangs #5001

Closed hklene closed 3 weeks ago

hklene commented 3 weeks ago

Setup

$ bash --version
GNU bash, version 5.2.26(1)-release (x86_64-pc-msys)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ git --version --build-options
git version 2.45.2.windows.1
cpu: x86_64
built from commit: 91d03cb2e4fbf6ad961ace739b8a646868cb154d
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.22631.3593]
# One of the following:
$ cat /etc/install-options.txt

Editor Option: Nano
Custom Editor Path:
Default Branch Option: trunk
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Rebase
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Enabled
Enable FSMonitor: Enabled

Issue was found in previous version of git 2.45.1 / bash 5.2.26(1)-release and reproduced also on virtual machine with Windows 10.0.19045.4412.

Could not reproduce in WSL with bash:

holger@BX-NB-015:/mnt/c/Users/holgerk$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
holger@BX-NB-015:/mnt/c/Users/holgerk$ uname -a
Linux BX-NB-015 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
holger@BX-NB-015:/mnt/c/Users/holgerk$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

Details

Bash with MinTTY

holgerk 09:30:37 OK 13 1619 ~
$ ls -Flag magic.txt text.log
-rw-r--r-- 1 1049089  65548 Jun 10 08:46 magic.txt
-rw-r--r-- 1 1049089 133219 Jun 10 08:46 text.log

holgerk 09:34:34 OK 14 1620 ~
$ md5sum magic.txt text.log
8ee7af38464d80a716d18d44c0a22f22 *magic.txt
0211535797c8d2e6b363f7dde147949f *text.log

holgerk 09:34:50 OK 15 1621 ~
$ wc -l magic.txt text.log
  2074 magic.txt
  4214 text.log
  6288 total

holgerk 09:36:20 OK 16 1622 ~
$ cat magic.txt | wc -l
2074

holgerk 09:36:40 OK 17 1623 ~
$ cat text.log | wc -l
4214

holgerk 09:36:49 OK 18 1624 ~
$ declare ctrl=$(cat text.log) && wc -l <<< "$ctrl"
4214

holgerk 09:38:00 OK 19 1625 ~
$ declare ctrl=$(cat magic.txt) && wc -l <<< "$ctrl"

holgerk 09:38:23  130  20 1626 ~
$ declare ctrl=$(cat magic.txt) && grep hallo <<< "$ctrl"

holgerk 09:41:34  130  21 1627 ~
$ declare ctrl=$(cat magic.txt) && cat <<< "$ctrl"

As demonstrated on the text.log or any other random text file, I want to count the lines.

If the contents of the magic.txt are stored in a bash variable and redirected as input to any other command (wc, grep, cat, ...) the process hangs indefinitely and has to be terminated with ctrl+C

I tried modifying the magic.txt. trying to shorten it further by deleting lines, but it always lost the magic. Only an extra line-break at the end was acceptable.

N/A

hklene commented 3 weeks ago

magic.txt

dscho commented 3 weeks ago

I just verified that this is happening in regular https://cygwin.com/ which, in this ticket's context is an upstream project of Git for Windows, as we use a slightly modified version of the Cygwin runtime as POSIX emulation layer that allows Bash to work.

@hklene would you mind reporting it there?

hklene commented 3 weeks ago

reported upstream: https://cygwin.com/pipermail/cygwin/2024-June/256104.html

dscho commented 3 weeks ago

reported upstream: https://cygwin.com/pipermail/cygwin/2024-June/256104.html

For readers like me who prefer the public-inbox UI: https://inbox.sourceware.org/cygwin/189fa51e-fada-4a5d-8208-a8f9c025bd64@towo.net/T/#m0da9b20fc6cf5b5ecc680b9ead8761cc7bd2e735

Since this is now reported in the appropriate place, I'll close this here ticket.