fix(windows): closing panes sometimes freezes wezterm
Based on #5977
Problem
On windows closing panes sometimes hangs wezterm.
These problem is related with how conpty.dll is being used this has been discussed in https://github.com/microsoft/terminal/discussions/17716
The problem seems to be mentioned in the docs at creating-a-pseudoconsole-session#ending-the-pseudoconsole-session
This pr
Hopefully will close #5882, could it help with related issues too #5496 #5432?
This pr manually closes handles before closing pseudoconsole to avoid that call from blocking.
Tasks
- [x] #5940 --> rename
- [x] #5977 --> read from output pipe before closing
- [ ] upgrade
conpty.dllNot strictly necessary to solve this issue in. Here leonard added instructions with the necessary steps to do that upgrade.
@RasmusN could you give a try to wezterm in this PR and see if helps with the problem where closing panes hang, I will be testing this over the coming week.
@RasmusN pr updated
@RasmusN did you have any issues with this build, so far using this pr today wezterm didn't hang for me anymore.
@RasmusN did you have any issues with this build, so far using this pr today wezterm didn't hang for me anymore.
I wasn't able to build it on my computer. I'm getting the following error:
error: failed to run custom build command for `openssl-sys v0.9.103`
Caused by:
process didn't exit successfully: `C:\Users\RasmusN\projects\wezterm\target\release\build\openssl-sys-36e52e0845de18a8\build-script-main` (exit code: 101)
Which has most likely nothing to do with your changes. However, I'll dig deeper into it tonight, looks like some perl library missing.
@RasmusN getting wezterm to build was a pain for me because of perl, but that issue should be gone with the latest release, did you install perl? Could you share a bit more of your error, that line doesn’t say much, you can share really long traces with a collapsible markdown block :)
@RasmusN getting wezterm to build was a pain for me because of perl, but that issue should be gone with the latest release, did you install perl? Could you share a bit more of your error, that line doesn’t say much, you can share really long traces with a collapsible markdown block :)
Sure!
output
$ cargo build --release
Compiling proc-macro2 v1.0.86
Compiling unicode-ident v1.0.12
Compiling cfg-if v1.0.0
Compiling windows_x86_64_msvc v0.52.6
Compiling jobserver v0.1.32
Compiling autocfg v1.3.0
Compiling serde v1.0.204
Compiling pkg-config v0.3.30
Compiling once_cell v1.19.0
Compiling cc v1.1.7
Compiling memchr v2.7.4
Compiling version_check v0.9.5
Compiling windows-targets v0.52.6
Compiling num-traits v0.2.19
Compiling windows-sys v0.52.0
Compiling getrandom v0.2.15
Compiling libc v0.2.155
Compiling futures-core v0.3.30
Compiling quote v1.0.36
Compiling pin-project-lite v0.2.14
Compiling syn v2.0.72
Compiling thiserror v1.0.63
Compiling winapi v0.3.9
Compiling crossbeam-utils v0.8.20
Compiling vcpkg v0.2.15
Compiling byteorder v1.5.0
Compiling zerocopy v0.7.35
Compiling log v0.4.22
Compiling futures-io v0.3.30
Compiling ahash v0.8.11
Compiling futures-sink v0.3.30
Compiling slab v0.4.9
Compiling allocator-api2 v0.2.18
Compiling smallvec v1.13.2
Compiling lock_api v0.4.12
Compiling libz-sys v1.1.18
Compiling scopeguard v1.2.0
Compiling hashbrown v0.14.5
Compiling fastrand v2.1.0
Compiling bitflags v1.3.2
Compiling anyhow v1.0.86
Compiling typenum v1.17.0
Compiling syn v1.0.109
Compiling concurrent-queue v2.5.0
Compiling aho-corasick v1.1.3
Compiling tracing-core v0.1.32
Compiling parking v2.2.0
Compiling regex-syntax v0.8.4
Compiling rand_core v0.6.4
Compiling siphasher v0.3.11
Compiling phf_shared v0.11.2
Compiling rand v0.8.5
Compiling itoa v1.0.11
Compiling phf_generator v0.11.2
Compiling futures-channel v0.3.30
Compiling simd-adler32 v0.3.7
Compiling equivalent v1.0.1
Compiling strsim v0.11.1
Compiling futures-task v0.3.30
Compiling regex-automata v0.4.7
Compiling pin-utils v0.1.0
Compiling fnv v1.0.7
Compiling indexmap v2.2.6
Compiling serde_derive v1.0.204
Compiling thiserror-impl v1.0.63
Compiling bytemuck_derive v1.7.0
Compiling tracing-attributes v0.1.27
Compiling futures-macro v0.3.30
Compiling bytemuck v1.16.1
Compiling event-listener v5.3.1
Compiling futures-util v0.3.30
Compiling num-integer v0.1.46
Compiling tracing v0.1.40
Compiling openssl-src v300.3.1+3.3.1
Compiling winreg v0.10.1
Compiling lazy_static v1.5.0
Compiling arrayvec v0.7.4
Compiling openssl-sys v0.9.103
Compiling event-listener-strategy v0.5.2
Compiling winapi-util v0.1.8
Compiling atomic-waker v1.1.2
Compiling utf8parse v0.2.2
Compiling adler v1.0.2
Compiling miniz_oxide v0.7.4
Compiling num-bigint v0.4.6
Compiling profiling-procmacros v1.0.15
Compiling socket2 v0.5.7
Compiling futures-lite v2.3.0
Compiling spin v0.9.8
Compiling bitflags v2.6.0
error: failed to run custom build command for openssl-sys v0.9.103
Caused by:
process didn't exit successfully: C:\Users\RasmusNordström\projects\wezterm\target\release\build\openssl-sys-36e52e0845de18a8\build-script-main (exit code: 101)
--- stdout
cargo:rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_OCB", "OPENSSL_NO_SM4", "OPENSSL_NO_SEED", "OPENSSL_NO_CHACHA", "OPENSSL_NO_CAST", "OPENSSL_NO_IDEA", "OPENSSL_NO_CAMELLIA", "OPENSSL_NO_RC4", "OPENSSL_NO_BF", "OPENSSL_NO_PSK", "OPENSSL_NO_DEPRECATED_3_0", "OPENSSL_NO_SCRYPT", "OPENSSL_NO_SM3", "OPENSSL_NO_RMD160", "OPENSSL_NO_EC2M", "OPENSSL_NO_OCSP", "OPENSSL_NO_CMS",
"OPENSSL_NO_COMP", "OPENSSL_NO_SOCK", "OPENSSL_NO_STDIO"))
cargo:rustc-check-cfg=cfg(openssl)
cargo:rustc-check-cfg=cfg(libressl)
cargo:rustc-check-cfg=cfg(boringssl)
cargo:rustc-check-cfg=cfg(libressl250)
cargo:rustc-check-cfg=cfg(libressl251)
cargo:rustc-check-cfg=cfg(libressl252)
cargo:rustc-check-cfg=cfg(libressl261)
cargo:rustc-check-cfg=cfg(libressl270)
cargo:rustc-check-cfg=cfg(libressl271)
cargo:rustc-check-cfg=cfg(libressl273)
cargo:rustc-check-cfg=cfg(libressl280)
cargo:rustc-check-cfg=cfg(libressl281)
cargo:rustc-check-cfg=cfg(libressl291)
cargo:rustc-check-cfg=cfg(libressl310)
cargo:rustc-check-cfg=cfg(libressl321)
cargo:rustc-check-cfg=cfg(libressl332)
cargo:rustc-check-cfg=cfg(libressl340)
cargo:rustc-check-cfg=cfg(libressl350)
cargo:rustc-check-cfg=cfg(libressl360)
cargo:rustc-check-cfg=cfg(libressl361)
cargo:rustc-check-cfg=cfg(libressl370)
cargo:rustc-check-cfg=cfg(libressl380)
cargo:rustc-check-cfg=cfg(libressl381)
cargo:rustc-check-cfg=cfg(libressl382)
cargo:rustc-check-cfg=cfg(libressl390)
cargo:rustc-check-cfg=cfg(libressl400)
cargo:rustc-check-cfg=cfg(ossl101)
cargo:rustc-check-cfg=cfg(ossl102)
cargo:rustc-check-cfg=cfg(ossl102f)
cargo:rustc-check-cfg=cfg(ossl102h)
cargo:rustc-check-cfg=cfg(ossl110)
cargo:rustc-check-cfg=cfg(ossl110f)
cargo:rustc-check-cfg=cfg(ossl110g)
cargo:rustc-check-cfg=cfg(ossl110h)
cargo:rustc-check-cfg=cfg(ossl111)
cargo:rustc-check-cfg=cfg(ossl111b)
cargo:rustc-check-cfg=cfg(ossl111c)
cargo:rustc-check-cfg=cfg(ossl111d)
cargo:rustc-check-cfg=cfg(ossl300)
cargo:rustc-check-cfg=cfg(ossl310)
cargo:rustc-check-cfg=cfg(ossl320)
cargo:rustc-check-cfg=cfg(ossl330)
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR
X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR unset
cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
OPENSSL_NO_VENDOR unset
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_CONFIG_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_CONFIG_DIR unset
cargo:rerun-if-env-changed=OPENSSL_CONFIG_DIR
OPENSSL_CONFIG_DIR unset
running "perl" "./Configure" "--prefix=C:/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/install" "--openssldir=SYS$MANAGER:[OPENSSL]" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-capieng" "no-asm" "VC-WIN64A"
--- stderr Can't locate Locale/Maketext/Simple.pm in @INC (you may need to install the Locale::Maketext::Simple module) (@INC entries checked: /c/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/build/src/util/perl /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl /c/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/build/src/external/perl/Text-Template-1.56/lib) at /usr/share/perl5/core_perl/Params/Check.pm line 6. BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/Params/Check.pm line 6. Compilation failed in require at /usr/share/perl5/core_perl/IPC/Cmd.pm line 59. BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/IPC/Cmd.pm line 59. Compilation failed in require at /c/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/build/src/util/perl/OpenSSL/config.pm line 19. BEGIN failed--compilation aborted at /c/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/build/src/util/perl/OpenSSL/config.pm line 19. Compilation failed in require at ./Configure line 23. BEGIN failed--compilation aborted at ./Configure line 23. thread 'main' panicked at C:\Users\RasmusNordström.cargo\registry\src\index.crates.io-6f17d22bba15001f\openssl-src-300.3.1+3.3.1\src\lib.rs:621:9:
Error configuring OpenSSL build: Command: "perl" "./Configure" "--prefix=C:/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/install" "--openssldir=SYS$MANAGER:[OPENSSL]" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-capieng" "no-asm" "VC-WIN64A" Exit status: exit code: 2
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
edit: Managed to solve the issue above by installing strawberryperl... however I got stuck on this:
Caused by: process didn't exit successfully: C:\Users\RasmusNordström\projects\wezterm\target\release\build\openssl-sys-36e52e0845de18a8\build-script-main (exit code: 101) --- stdout cargo:rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_OCB", "OPENSSL_NO_SM4", "OPENSSL_NO_SEED", "OPENSSL_NO_CHACHA", "OPENSSL_NO_CAST", "OPENSSL_NO_IDEA", "OPENSSL_NO_CAMELLIA", "OPENSSL_NO_RC4", "OPENSSL_NO_BF", "OPENSSL_NO_PSK", "OPENSSL_NO_DEPRECATED_3_0", "OPENSSL_NO_SCRYPT", "OPENSSL_NO_SM3", "OPENSSL_NO_RMD160", "OPENSSL_NO_EC2M", "OPENSSL_NO_OCSP", "OPENSSL_NO_CMS", "OPENSSL_NO_COMP", "OPENSSL_NO_SOCK", "OPENSSL_NO_STDIO")) cargo:rustc-check-cfg=cfg(openssl) cargo:rustc-check-cfg=cfg(libressl) cargo:rustc-check-cfg=cfg(boringssl) cargo:rustc-check-cfg=cfg(libressl250) cargo:rustc-check-cfg=cfg(libressl251) cargo:rustc-check-cfg=cfg(libressl252) cargo:rustc-check-cfg=cfg(libressl261) cargo:rustc-check-cfg=cfg(libressl270) cargo:rustc-check-cfg=cfg(libressl271) cargo:rustc-check-cfg=cfg(libressl273) cargo:rustc-check-cfg=cfg(libressl280) cargo:rustc-check-cfg=cfg(libressl281) cargo:rustc-check-cfg=cfg(libressl291) cargo:rustc-check-cfg=cfg(libressl310) cargo:rustc-check-cfg=cfg(libressl321) cargo:rustc-check-cfg=cfg(libressl332) cargo:rustc-check-cfg=cfg(libressl340) cargo:rustc-check-cfg=cfg(libressl350) cargo:rustc-check-cfg=cfg(libressl360) cargo:rustc-check-cfg=cfg(libressl361) cargo:rustc-check-cfg=cfg(libressl370) cargo:rustc-check-cfg=cfg(libressl380) cargo:rustc-check-cfg=cfg(libressl381) cargo:rustc-check-cfg=cfg(libressl382) cargo:rustc-check-cfg=cfg(libressl390) cargo:rustc-check-cfg=cfg(libressl400) cargo:rustc-check-cfg=cfg(ossl101) cargo:rustc-check-cfg=cfg(ossl102) cargo:rustc-check-cfg=cfg(ossl102f) cargo:rustc-check-cfg=cfg(ossl102h) cargo:rustc-check-cfg=cfg(ossl110) cargo:rustc-check-cfg=cfg(ossl110f) cargo:rustc-check-cfg=cfg(ossl110g) cargo:rustc-check-cfg=cfg(ossl110h) cargo:rustc-check-cfg=cfg(ossl111) cargo:rustc-check-cfg=cfg(ossl111b) cargo:rustc-check-cfg=cfg(ossl111c) cargo:rustc-check-cfg=cfg(ossl111d) cargo:rustc-check-cfg=cfg(ossl300) cargo:rustc-check-cfg=cfg(ossl310) cargo:rustc-check-cfg=cfg(ossl320) cargo:rustc-check-cfg=cfg(ossl330) cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR unset cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR OPENSSL_NO_VENDOR unset cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_CONFIG_DIR X86_64_PC_WINDOWS_MSVC_OPENSSL_CONFIG_DIR unset cargo:rerun-if-env-changed=OPENSSL_CONFIG_DIR OPENSSL_CONFIG_DIR unset openssl-src: Enable the assembly language routines in building OpenSSL. running "perl" "./Configure" "--prefix=C:/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/install" "--openssldir=SYS$MANAGER:[OPENSSL]" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-capieng" "VC-WIN64A"
--- stderr Can't open perl script "./Configure": No mapping for the Unicode character exists in the target multi-byte code page.
thread 'main' panicked at C:\Users\RasmusNordström.cargo\registry\src\index.crates.io-6f17d22bba15001f\openssl-src-300.3.1+3.3.1\src\lib.rs:621:9:
Error configuring OpenSSL build: Command: "perl" "./Configure" "--prefix=C:/Users/RasmusNordström/projects/wezterm/target/release/build/openssl-sys-57b7ba868798cc12/out/openssl-build/install" "--openssldir=SYS$MANAGER:[OPENSSL]" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-capieng" "VC-WIN64A" Exit status: exit code: 0xffffffff
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace warning: build failed, waiting for other jobs to finish...
It seems to be an unicode issue (like its 1998) with the path name C:\Users\RasmusNordström\...
I was able to build it and have not experienced another hang. Before it would hang pretty consistently when the panes had some processes running. Thanks!
It seems to be an unicode issue (like its 1998) with the path name
C:\Users\RasmusNordström\...
@RasmusN being on a non US/UK setup is never fun, lately I faced https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/135 which is now solved, that kept me from building wezterm for a while.
Colleagues with special characters faced also this one https://github.com/fastapi/typer/pull/277.
Now again ö getting on the way with a build depending on perl.
If you can rename your user and feel fine make an aberration with your last name, just rename your username ö -> o or oe.
If you can't, try at least to move your projects folder to another location C:/Users/RasmusNordström/projects/ --> C:/projects/ and see if that helps,
In short, if it's not to risky to rename your user, do that; that will save you trouble for the future.
I was able to build it and have not experienced another hang. Before it would hang pretty consistently when the panes had some processes running. Thanks!
Thank mostly @lhecker for this one, he basically spotted where the problem was and told me exactly what to do about it.
👋 @wez & @Cammisuli I hope you don't find my @ to you impolite, probably you are quite busy or this PR might have gone unnoticed under your radar.
PR summary
When closing wezterm panes on windows it's quite common to see wezterm hanging indefinitely.
After this pr wezterm will not freeze when closing panes on windows, the solution was proposed by @lhecker, one of the main contributors to https://github.com/microsoft/terminal where conpty code lives.
@clemenscodes and me can confirm that we don't see wezterm freeze anymore.
Given the above I think this PR is ready for you to have a look when you have time.
In short, if it's not to risky to rename your user, do that; that will save you trouble for the future.
Sorry for late reply. I'm using a computer from work so I'm not able to change username. I was able to move it there with an admin account but then I realized I would have to reinstall cargo, VS C++ dev kit, etc on the admin account...
Anyway, great job with both finding the bug and providing a solution @FrancescElies! Hopefully this will be merged as soon as possible. I'm starting to get a bit tired of submitting a tiny prayer before closing a pane/tab.
@RasmusN we use windows at work too.
. I'm starting to get a bit tired of submitting a tiny prayer before closing a pane/tab.
I feel your pain, if it wouldn't be because there is no viable alternative to wezterm, something with tmux like capabilities that works crossplatform across the the big three windows, linux & macos I would have probably moved on to something else.
In the meanwhile until I ge approval to run on ci this pr you can download it from ci in my fork, see here at the bottom of the page you have an installer, could you give it a try?
In the meanwhile until I ge approval to run on ci this pr you can download it from ci in my fork, see here at the bottom of the page you have an installer, could you give it a try?
Awesome, thanks! Will try it out and get back to you.
I've used it the whole day, not a single freeze so far.
Thanks for this!
While I'm not opposed to some low level poking, if this is fixed with an updated conpty.dll, I think I'd rather just update that dll and avoid this complexity, and also avoid having to later remember to resolve this properly.
Last time conpty was updated was in e7fe7c07da2da071d75c88ff3ae7a3c0e74d4f1f using pre-built binaries that @dhowett published. I'd like to grab a newer version of those and update, but I'm not sure how best to locate the current version if any has been updated since we conducted the initial experiment with this!
I understand, i would gladly try to upgrade conpty myself but I won’t be able to do that until April next year.
I've used this branch for two months now, and did not experience a single crash. Thanks for making this fix @FrancescElies so we have a crash free wezterm experience on windows.
I've used this branch for two months now, and did not experience a single crash. Thanks for making this fix @FrancescElies so we have a crash free wezterm experience on windows.
Same here, working flawlessly. This has been a huge value for me, I hope more people find this PR.
I hope that Wez creates an org for Wezterm or something and finds more maintainers. Excellent prs have been stuck there for ages..
Commenting to bump this PR. Wezterm hangs are the only reason I'm not using it on Windows.
ETA: To clarify, this is a gentle bump just to make sure the PR stays active, not a discontented user demanding a PR get merged asap. Happy holidays :)
I wish I'd seen this before 😢 (8 opened tabs in an highly focused session)
Are there any updates on this please. For me it is still freezes randomly!
@FrancescElies I updated conpty yesterday. Can you rebase and review this PR to see if we need any of the hacky parts now? Thank you!
Great ! I've been having some random issues here and there with wezterm hanging, it was never annoying enough to switch to this PR but I kept it in mind and saved my work often ; I remember reading this thread months ago, when it was still being investigated.
Really funny that my wezterm crashed a couple hours after wez posted this message, it knows it won't be able to crash out for long and is trying to go out with a flame 😆
Despite the (understandable, it's open source ! ) delays, thanks for the great work with WezTerm. I love the cross-compatibility, and the simplicity of lua is hard to go back from :)
@wez i will have a look into it in April, best wishes.
I am still dealing with this freezing issue after closing tabs in certain cases! Hope this fix gets merged soon.
In the meantime you can use the binary from this pr, i posted the link somewhere above in this thread.
The artifact on your link expired, is it possible to upload it again ? Thanks
@wez i will have a look into it in April, best wishes.
Just checking in, what's the status of this?
@RasmusN just fyi -- I installed the latest nightly build, and now I no longer get the crashes.