git-for-windows / git

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

error: cannot spawn git: Invalid argument #1481

Closed MagicAndre1981 closed 6 years ago

MagicAndre1981 commented 6 years ago

Setup

$ git --version --build-options
git version 2.16.1.windows.2
cpu: x86_64
built from commit: e78e3c8ee9c219723d60aa1bccd8348c2269b9ba
sizeof-long: 4

Windows 8.1 x64

$ cmd.exe /c ver
Microsoft Windows [Version 6.3.9600]
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

C:\Users\André> type "C:\Program Files\Git\etc\install-options.txt"
Editor Option: Nano
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: WinSSL
CRLF Option: CRLFCommitAsIs
Bash Terminal Option: ConHost
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Enabled

n/a

Details

I get the error when using TortoiseGit to to a pull.

I get the error when using TortoiseGit to to a pull.

Pull works fine and I get the new changes pulled.

I get this error:

git.exe pull --progress -v --no-rebase "origin"

error: cannot spawn git: Invalid argument

git did not exit cleanly (exit code 1)

happens to all cloned repositories

garretwilson commented 6 years ago

I just ran into this with a fresh system with Git 2.16.1.windows.2 and TortoiseGit 2.5.7.0.

I note that someone has also asked about this problem on Stack Overflow.

garretwilson commented 6 years ago

Interestingly when I run the same command TortoiseGit claims it is running from the command line, it executes successfully:

git.exe pull --progress -v --no-rebase "origin"

But still TortoiseGit shows an error:

error: cannot spawn git: Invalid argument

git did not exit cleanly (exit code 1) (63 ms @ 2/6/2018 7:23:08 AM)

Maybe this version of Git is not returning the correct error code.

MagicAndre1981 commented 6 years ago

thanks for the link @garretwilson . I did the downgrade to 2.16.0.2 as suggested in the SO topic and it works again.

dscho commented 6 years ago

Isn't this a duplicate of #1475?

MagicAndre1981 commented 6 years ago

I run 8.1 and I don't get "Function not implemented". I have no idea if this is a duplicate. can we get a nightly build to test it?

dscho commented 6 years ago

Due to unfortunate other problems, the snapshot builds did not work recently, so there are no current snapshots.

However, what is there is a new version: v2.16.1(3), just released. It's just out of the oven, you may have to wait a little until it cools off ;-)

Seriously again, if you could try that one, and report back, that would be awesome.

MagicAndre1981 commented 6 years ago

@dscho it is NO duplicate. I just installed Git-2.16.1.3-64-bit.exe and still get the same error message

MagicAndre1981 commented 6 years ago

I did the downgrade to Git-2.16.1-64-bit.exe and this also fixes the issue. So there is a regression between 2.16.1 and 2.16.2

MagicAndre1981 commented 6 years ago

@dscho I've tried Git-2.16.1.3-64-bit.exe on my Windows 10 v1709 VM and I get the same error. So this is no issue related to Windows 8.1 and no duplicate.

dscho commented 6 years ago

So this is no issue related to Windows 8.1 and no duplicate.

sigh I just released a new Git for Windows version! Can't I ever have a good version?

Can you see (e.g. using Process Monitor) which git.exe is called (there are a couple of 'em...) in the working vs non-working case?

Bendor commented 6 years ago

The same problem on Windows 10 with Git-2.16.1.2-64-bit.exe and Git-2.16.1.3-64-bit.exe build

Tim-bflow commented 6 years ago

Same thing here. I can no longer Push anything because I need to Pull first and have clients waiting on my updates...

ghost commented 6 years ago

Same problem here

git stash push
error: cannot spawn git-stash: Invalid argument
Windows 10 1709 x64
MinGit busybox 2.16.1(3) x64
TortoiseGit 2.5.7 Beta x64
dscho commented 6 years ago

MinGit busybox 2.16.1(3) x64

Wait, are y'all talking about BusyBox-backed MinGit? Why is this the first time anybody tells me about this!

TCHessen commented 6 years ago

No. I had the same issue on Windows 10 without the busybox build.

dscho commented 6 years ago

@TCHessen could you kindly describe your setup precisely? And also verify that things still do not work correctly with PortableGit v2.16.1(3)?

TCHessen commented 6 years ago

Sure. I used TortoiseGIT 2.5.7 and

git version 2.16.1.windows.3 cpu: x86_64 built from commit: dc364ab06b41bcd142295751cef12e2c88fdc437 sizeof-long: 4

Any other infos needed?

dscho commented 6 years ago

Does TortoiseGit really play a role, or does it also occur if you use Git Bash or Git CMD directly?

BTW if you want, we can head over to https://gitter.im/git-for-windows/git and discuss more interactively. I would like to get to the bottom of this, and if you can help me with that, I will be very grateful.

TCHessen commented 6 years ago

TortoiseGIT plays a role, but I cannot say more. On the command line there occurs no error. C:...\xxx>"C:\Program Files\Git\bin\git.exe" pull --progress -v --no-rebase "origin" From https://git.sittig.local/Web/xxx = [up to date] master -> origin/master Already up to date.

ghost commented 6 years ago

I can confirm this. git stash push is also working well when called from cmd.exe

aimbin commented 6 years ago

After I update git to windows3(Git-2.16.1.3-64-bit.exe), still can not use git-tortoise to pull. But can do git remote show and git pull in command line.

dscho commented 6 years ago

TortoiseGIT plays a role, but I cannot say more.

Could you use the Process Monitor to log what is happening while TortoiseGit exposes that problem, then right-click on the git.exe that is spawned to verify its location? It could be that TortoiseGit bundles its own MinGit, after all.

dscho commented 6 years ago

@aimbin thank you for confirming. At this point, I would like to reduce the "#metoo" chatter, though, as I already know that it is a big problem, and do not need to be reminded of it. What I need is more information to recreate the problem here so I can work on a fix. Thank you.

dscho commented 6 years ago

I did the downgrade to 2.16.0.2 as suggested in the SO topic and it works again.

@MagicAndre1981 can you confirm or deny that downgrading to v2.16.1 works?

People, I need your help.

TCHessen commented 6 years ago

TortoiseGIT spawns "C:\Program Files\Git\bin\git.exe" pull --progress -v --no-rebase "origin" , I can confirm it with the ProcessMonitor. And only dll locates in windows path or git path are included.

ghost commented 6 years ago

@dscho I can confirm that v2.16.1 woks

dscho commented 6 years ago

I did the downgrade to Git-2.16.1-64-bit.exe and this also fixes the issue. So there is a regression between 2.16.1 and 2.16.2

Oh, nevermind @MagicAndre1981 I should have tried to read more closely. So yes, the problem is most likely that the code to try to avoid those locking issues somehow does not like the standard handles passed in by TortoiseGit.

@TCHessen thank you for confirming. Let me build a custom installer for you, with a tentative fix.

dscho commented 6 years ago

Okay, here it is: https://github.com/dscho/git/releases/tag/attempt-to-work-around-1481-v1

If it does not work (or if it does, and you are willing to help me even further), can you set the config variable config.debug1481 = true in the repository and run the Git operation again? The debug output should help me identify the root cause.

ghost commented 6 years ago
git.exe stash push

error: spawn2 not even attempted
error: cannot spawn git-stash: Invalid argument

config.debug1481 = true doesn't seem to have an effect on this output

TCHessen commented 6 years ago

With TortoiseGIT:

git.exe pull --progress -v --no-rebase "origin"

warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 From https://git.yyy.local/Web/xxx = [up to date] master -> origin/master warning: ret: 0, restrict 1, #count: 2, err: 87 error: error: 87 error: #stdhandles: 2 error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0) error: handle #1: 00000000000005c8 (file type 3, get handle info 1: 0) warning: spawn2 successful, err: 6 warning: ret: 0, restrict 1, #count: 2, err: 87 error: error: 87 error: #stdhandles: 2 error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0) error: handle #1: 00000000000005c8 (file type 3, get handle info 1: 0) warning: spawn2 successful, err: 6 Already up to date. warning: ret: 1, restrict 0, #count: 2, err: 0

Success (1594 ms @ 07.02.2018 12:18:15)

With cmd.exe

C:...\xxx>"C:\Program Files\Git\bin\git.exe" pull --progress -v --no-rebase "origin" warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 From https://git.yyy.local/Web/xxx = [up to date] master -> origin/master warning: ret: 1, restrict 1, #count: 3, err: 122 warning: ret: 1, restrict 1, #count: 3, err: 122 Already up to date.

toouur commented 6 years ago

Hi there, I was the one who raised the question on SO. I can confirm, that the pull worked just fine both from git bash and git cmd. Also, it seems like working with tortoise if you do it with fetch rebase (recheck it please). I haven't downgraded on my home PC yet because it's not critical for me.

dscho commented 6 years ago

@0x084E thanks for testing. Can you try with git.exe -c core.debug1481=true stash push?

error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)

@TCHessen now, this is fascinating. I never knew that you could pass in such a handle. INVALID_HANDLE_VALUE corresponds to ffffffffffffffff (i.e. the unsigned version of -1), while this is -2. I wonder where that comes from.

ghost commented 6 years ago

@dscho git.exe -c core.debug1481=true stash push with cmd.exe works as expected and doesn't produce any further output. With Tortoise I cannot add additional arguments. It produces the output above. If tried to set debug1481 at repo and user level, but output doesn't change. Am I doing somthing wrong? The config looks like this:

[core]
  debug1481 = true

Edit: With git.exe fetch -v --progress "origin" a get additional output, so config seems to work

warning: ret: 1, restrict 1, #count: 3, err: 5
warning: ret: 1, restrict 1, #count: 3, err: 0
warning: ret: 1, restrict 1, #count: 3, err: 0
warning: ret: 1, restrict 1, #count: 3, err: 5
warning: ret: 1, restrict 1, #count: 3, err: 0
= [up to date]          master            -> origin/master
warning: ret: 0, restrict 1, #count: 2, err: 87
error: error: 87
error: #stdhandles: 2
error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)
error: handle #1: 0000000000000604 (file type 3, get handle info 1: 0)
warning: spawn2 successful, err: 0
dscho commented 6 years ago

git.exe -c core.debug1481=true stash push with cmd.exe works as expected and doesn't produce any further output

That is not expected. git.exe stash should always spawn something. If it does not even show the "spawn2 not even attempted" message, something is really wrong, as in: this is probably not that git.exe you just installed from that custom installer.

The config looks like this:

[core]
  debug1481 = true

If the patched git.exe is running, that should indeed provide plenty of debug output.

TCHessen commented 6 years ago

I did exactly the same and got the debug output. I hope that it helps.

ghost commented 6 years ago

@dscho see edit, for other commands i get an output if checked this multiple times now, with other commands i get additional output but not with stash, not with stash push and not with stash pop. But I can see that it spawns multiple git processes. I've also checked multiple times that it uses always the same git install.

dscho commented 6 years ago

@0x084E ah, maybe the problem is that the config variable is not parsed in time. That must be the problem, definitely, yes, as git-stash is a Unix shell script, and at that point we do not parse the config lest we taint commands that do not even need a Git directory...

I'll have a look at the edited output.

dscho commented 6 years ago

@0x084E sadly, the edits did not come through automatically. I had to reload the entire page. Could I ask you a favor? Just add comments, instead of editing them... 😄

error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)

Aha! That's the same symptom as in the TortoiseGit case.

What is your setup? You are not using TortoiseGit, correct? So which terminal do you use?

ghost commented 6 years ago

OK, will do next time 😄 sorry for confusion, the output above comes from TortoiseGit. If I don't use TortoiseGit I use cmd.exe which works fine in all cases I've tried so far.

dscho commented 6 years ago

BTW @TCHessen @0x084E I uploaded another custom installer here: https://github.com/dscho/git/releases/tag/attempt-to-work-around-1481-v2

It should print more information on the funny handle. Could you test, please?

dscho commented 6 years ago

sorry for confusion, the output above comes from TortoiseGit.

@0x084E thanks for the clarification! You probably mentioned it somewhere in the thread, and my congested sinuses prevent me from holding all the information in my working memory. Sorry about that.

ghost commented 6 years ago

output from git.exe fetch -v --progress "origin" (with TortoiseGit)

warning: get_osf_handle for 7 (fd_is_interactive 0 0): 0000000000000284 (0000000000000000 0000000000000000)
warning: fhin: 7, hstdInput: 0000000000000284
warning: get_osf_handle for 8 (fd_is_interactive 0 0): 0000000000000288 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000594 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 5
warning: get_osf_handle for 9 (fd_is_interactive 0 0): 0000000000000090 (0000000000000000 0000000000000000)
warning: fhin: 9, hstdInput: 0000000000000090
warning: get_osf_handle for 10 (fd_is_interactive 0 0): 0000000000000094 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000594 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 0
warning: get_osf_handle for 10 (fd_is_interactive 0 0): 0000000000000078 (0000000000000000 0000000000000000)
warning: fhin: 10, hstdInput: 0000000000000078
warning: get_osf_handle for 12 (fd_is_interactive 0 0): 0000000000000158 (0000000000000000 0000000000000000)
warning: get_osf_handle for 11 (fd_is_interactive 0 0): 000000000000015c (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 0
warning: get_osf_handle for 5 (fd_is_interactive 0 0): 000000000000027c (0000000000000000 0000000000000000)
warning: fhin: 5, hstdInput: 000000000000027c
warning: get_osf_handle for 6 (fd_is_interactive 0 0): 0000000000000290 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000594 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 5
warning: get_osf_handle for 11 (fd_is_interactive 0 0): 0000000000000198 (0000000000000000 0000000000000000)
warning: fhin: 11, hstdInput: 0000000000000198
warning: get_osf_handle for 12 (fd_is_interactive 0 0): 000000000000019c (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000594 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 0
= [up to date]          develop            -> origin/develop
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 0000000000000594 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000594 (0000000000000000 0000000000000000)
warning: ret: 0, restrict 1, #count: 2, err: 87
error: error: 87
error: #stdhandles: 2
error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)
error: handle #1: 0000000000000594 (file type 3, get handle info 1: 0)
warning: spawn2 successful, err: 0
TCHessen commented 6 years ago
git.exe pull --progress -v --no-rebase "origin"

warning: get_osf_handle for 7 (fd_is_interactive 0 0): 0000000000000274 (0000000000000000 0000000000000000)
warning: fhin: 7, hstdInput: 0000000000000274
warning: get_osf_handle for 8 (fd_is_interactive 0 0): 0000000000000278 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 5 (fd_is_interactive 0 0): 0000000000000264 (0000000000000000 0000000000000000)
warning: fhin: 5, hstdInput: 0000000000000264
warning: get_osf_handle for 6 (fd_is_interactive 0 0): 0000000000000278 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 7 (fd_is_interactive 0 0): 0000000000000160 (0000000000000000 0000000000000000)
warning: fhin: 7, hstdInput: 0000000000000160
warning: get_osf_handle for 8 (fd_is_interactive 0 0): 0000000000000164 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 8 (fd_is_interactive 0 0): 0000000000000150 (0000000000000000 0000000000000000)
warning: fhin: 8, hstdInput: 0000000000000150
warning: get_osf_handle for 10 (fd_is_interactive 0 0): 0000000000000160 (0000000000000000 0000000000000000)
warning: get_osf_handle for 9 (fd_is_interactive 0 0): 0000000000000164 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 5 (fd_is_interactive 0 0): 0000000000000268 (0000000000000000 0000000000000000)
warning: fhin: 5, hstdInput: 0000000000000268
warning: get_osf_handle for 6 (fd_is_interactive 0 0): 0000000000000278 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 9 (fd_is_interactive 0 0): 0000000000000080 (0000000000000000 0000000000000000)
warning: fhin: 9, hstdInput: 0000000000000080
warning: get_osf_handle for 10 (fd_is_interactive 0 0): 000000000000006c (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
From https://git.yyy.local/Web/xxx_XOVIS
= [up to date]      master     -> origin/master
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 0, restrict 1, #count: 2, err: 87
error: error: 87
error: #stdhandles: 2
error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)
error: handle #1: 0000000000000598 (file type 3, get handle info 1: 0)
warning: spawn2 successful, err: 6
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 0, restrict 1, #count: 2, err: 87
error: error: 87
error: #stdhandles: 2
error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)
error: handle #1: 0000000000000598 (file type 3, get handle info 1: 0)
warning: spawn2 successful, err: 6
Already up to date.
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 0000000000000598 (0000000000000000 0000000000000000)
warning: ret: 1, restrict 0, #count: 2, err: 0

Success (1812 ms @ 07.02.2018 13:19:31)
MagicAndre1981 commented 6 years ago

here is my output of v2 of your debug exe with debug1481 = true set in config:

$  git --version --build-options
git version 2.16.1.windows.2.9.g0922cb34ea0
cpu: x86_64
built from commit: 0922cb34ea0aad80997bb8bb3df4ac6f143d6c40
sizeof-long: 4
git.exe pull --progress -v --no-rebase "origin"

warning: get_osf_handle for 8 (fd_is_interactive 0 0): 0000000000000148 (0000000000000000 0000000000000000)
warning: fhin: 8, hstdInput: 0000000000000148
warning: get_osf_handle for 9 (fd_is_interactive 0 0): 000000000000014c (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 9 (fd_is_interactive 0 0): 0000000000000138 (0000000000000000 0000000000000000)
warning: fhin: 9, hstdInput: 0000000000000138
warning: get_osf_handle for 11 (fd_is_interactive 0 0): 0000000000000148 (0000000000000000 0000000000000000)
warning: get_osf_handle for 10 (fd_is_interactive 0 0): 000000000000014c (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
warning: get_osf_handle for 10 (fd_is_interactive 0 0): 000000000000014c (0000000000000000 0000000000000000)
warning: fhin: 10, hstdInput: 000000000000014c
warning: get_osf_handle for 11 (fd_is_interactive 0 0): 0000000000000148 (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: ret: 1, restrict 1, #count: 3, err: 122
From https://github.com/telerik/xamarin-sdk
= [up to date]      master     -> origin/master
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: ret: 0, restrict 1, #count: 2, err: 87
error: error: 87
error: #stdhandles: 2
error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)
error: handle #1: 000000000000053c (file type 3, get handle info 1: 0)
warning: spawn2 successful, err: 6
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: ret: 0, restrict 1, #count: 2, err: 87
error: error: 87
error: #stdhandles: 2
error: handle #0: fffffffffffffffe (file type 0, get handle info 1: 0)
error: handle #1: 000000000000053c (file type 3, get handle info 1: 0)
warning: spawn2 successful, err: 0
Already up to date.
warning: get_osf_handle for 0 (fd_is_interactive 0 0): fffffffffffffffe (0000000000000000 0000000000000000)
warning: fhin: 0, hstdInput: fffffffffffffffe
warning: get_osf_handle for 1 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: get_osf_handle for 2 (fd_is_interactive 0 0): 000000000000053c (0000000000000000 0000000000000000)
warning: ret: 1, restrict 0, #count: 2, err: 0

Success (1516 ms @ 07.02.2018 13:32:38)
dscho commented 6 years ago

Thanks. This is getting really weird. So something either in Git or in TortoiseGit sets the handle to (HANDLE)-2... Let's see whether I can find some code that might do that.

MagicAndre1981 commented 6 years ago

if you can build a version with generated PDBs and provide the PDBs for that version I can use ETW to do handle tracing with callstack so I could maybe see some details in Windows Performance Analyzer.

dscho commented 6 years ago

@MagicAndre1981 good idea. It is not quite straight-forward to do that yet, but I'll use a work-around.

In the meantime, I dug out the source code in TortoiseGit that seems to be responsible for calling git.exe: https://github.com/TortoiseGit/TortoiseGit/blob/b2d00f8785e2b148e5555925a3be7fbebca7a29f/src/Git/Git.cpp#L281-L375

As far as I can see, hStdInput is initialized to 0, and never set again: https://github.com/TortoiseGit/TortoiseGit/blob/b2d00f8785e2b148e5555925a3be7fbebca7a29f/src/Git/Git.cpp#L305

However, the documentation for STARTF_USESTDHANDLES in STARTUPINFO's documentation says this:

If this flag is specified when calling the GetStartupInfo function, these members are either the handle value specified during process creation or INVALID_HANDLE_VALUE.

... which suggests to me that hStdInput should either be set to a valid HANDLE or to INVALID_HANDLE_VALUE (which is -1, not 0). So maybe it comes from there?

@MagicAndre1981 let me get that custom build with PDBs to you. Note, however, that those are custom PDBs, as Git for Windows is built using GCC (which does not output PDBs) and the PDB files are generated using cv2pdb. So hopefully they will have enough information in them for you to do your magic.

TCHessen commented 6 years ago

But since this issue occurs in version 2.16.2 and 2.16.3 and not in 2.16.1 a diff should help to find the bug?

cs96and commented 6 years ago

I suspect it's related to this bug fix in 2.16.1.2...

When Git spawns processes, now only the necessary file handles are inherited from the parent process, possibly preventing file locking issues.

dscho commented 6 years ago

@TCHessen the bug is somewhere else than in the diff. I can show you the responsible code: https://github.com/git-for-windows/git/blob/dc364ab06b41bcd142295751cef12e2c88fdc437/compat/mingw.c#L1724-L1738

This code was introduced in v2.16.1(2), with the intention to avoid file locking issues. The thing is: if you spawn a new process, stating that you want it to inherit file handles, by default it inherits all of them. Not only of stdin/stdout/stderr. But also e.g. file handles to Git's .pack files. And the .git/index file, if it is still memory-mapped. And when the spawned process is not quitting quickly, the spawned process can prevent those files from being renamed, modified or deleted.

The new code tries to ensure that only stdin/stdout/stderr are inherited by child processes.

So the code really tries to address a long-standing bug.

The problem with the new code is that it failed to anticipate so many issues with specifying those handles:

These problems are really unfortunate, and quite honestly: unexpected. Nothing in the documentation prepared me for the hot-fixes required to patch up the issues.

So that's where we are. The new code intends to do the right thing, but needs to be adjusted to be a lot more fault-tolerant. And y'all are helping me greatly by being so responsive and testing and being patient. Thanks!