Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.5k stars 570 forks source link

ConEmuHk DLL injection makes Locale.exe hangs when ran in parallel #2520

Open Mikaz-fr opened 1 year ago

Mikaz-fr commented 1 year ago

This issue was originally discussed in Cmder context (https://github.com/cmderdev/cmder/issues/2670) before we realized it should have been opened here.

When using ConEmu 221218 standalone or within Cmder, if ConEmuHk injection is enabled, running locale.exe from Git-for-windows in multiple threads in parallel might hang. If ConEmuHk is disabled there is no such issue. This was found out when starting up ConEmu and restoring multiple tabs, if each tab at startup calls locale.exe (like it's the case with Cmder) then some tabs hangs and never show the prompt. Further testing showed that it can easily be reproduce by calling locale.exe in a loop from ConEmu and from a separate Cmd terminal (outside ConEmu).

The following bat script can be used to reproduce the issue by starting it in ConEmu and Cmd at the same time:

@echo off
set localePath=<PATH>\vendor\git-for-windows\usr\bin\locale.exe
for /l %%x in (1, 1, 100) do (
    echo Loop %%x / 100
    %localePath% -uU 2
)

The executable locale.exe from Git-for-windows can be found for example in the full Cmder zip file (https://github.com/cmderdev/cmder/releases/tag/v1.3.21).

The behavior is quite weird, sometime restarting locale.exe from ConEmu side would unblock the one running in Cmd. There seem to be some mutual locking that only happens if multiple instances run at the same time and ConEmuHk is injected.

Is this an issue that can be fixed from ConEmu side ?

chrisant996 commented 1 year ago

These comments have analysis about heap dumps that I received:

This comment has repro steps and observations about msys_2_0.dll containing the code that's hanging:

And even arch.exe experiences the hang -- it's not limited to just locale.exe. So there's something in MSYS in general that is somehow getting affected by conemuhk injection.

A next step that could reveal more info could be to either find symbols for msys_2_0, or to build MSYS locally and then examine the hang in a debugger, with matching symbols and source code to aid the investigation.