Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows): closing panes sometimes freezes wezterm #5977

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FrancescElies
Copy link

@FrancescElies FrancescElies commented Aug 16, 2024

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 microsoft/terminal#17716

The problem seems to be mentioned in the docs at creating-a-pseudoconsole-session#ending-the-pseudoconsole-session

image

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

@FrancescElies
Copy link
Author

@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.

Comment on lines 86 to 99
// read up to 1000 bytes
while let Ok(num_byes_read) = self.output.read(&mut buffer[..]) {
if num_byes_read == 0 {
break;
}
}
Copy link

@lhecker lhecker Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, because until recently you must read from the output pipe concurrently while ClosePseudoConsole is called. This is also true for the version of ConPTY that wezterm uses.

However, starting microsoft/terminal#17704 you can do something else: You can first call the new ClosePseudoConsole and then (on the same thread; not concurrently) read from the output pipe until it is closed on you (returns an error). Basically, you can do what you wrote, but with the order flipped.

If you don't want to upgrade ConPTY now, you can do something like this as a temporary workaround (pseudo-code; I keep forgetting what valid Rust syntax looks like lol):

fn drop(&mut self) {
    // A `HPCON` is a struct consisting of 3 HANDLEs:
    // A pipe for communicating with the PTY, a handle to keep it alive
    // until ClosePseudoConsole is called, and a process handle to the
    // underlying conhost process.
    unsafe {
        let handles = self.con as *mut [HANDLE; 3];
        for i in ..3 {
            CloseHandle(handles[i]);
            handles[i] = std::ptr::null();
        }
    }

    // read up to 1000 bytes
    while let Ok(num_byes_read) = self.output.read(&mut buffer[..]) {
        if num_byes_read == 0 {
            break;
        }
    }

    // This won't do anything but deallocate the handle.
    unsafe { (CONPTY.ClosePseudoConsole)(self.con) };
}

That aside, ReleasePseudoConsole is a new function which does the same as the unsafe code above but only for the 2nd handle (which keeps conhost alive). I've started writing documentation for it here: MicrosoftDocs/Console-Docs#323
Here's a preview of the documentation: https://github.com/MicrosoftDocs/Console-Docs/blob/dev/lhecker/24h2/docs/releasepseudoconsole.md

Ideally Wezterm should call ReleasePseudoConsole (or close the 2nd HPCON handle) right after attaching an application to ConPTY, about here: https://github.com/FrancescElies/wezterm/blob/a25e7be9bc6c68290ed465b6c1aa780cfee9b793/pty/src/win/pseudocon.rs#L189-L191

It should then stop returning a process handle from that function and not use it to track the shell/application lifetime anymore. Instead, it should read from the output pipe until the pipe has been closed on it by the PTY. If wezterm wants to kill all attached console applications prematurely (e.g. when closing the tab), it can call the upcoming non-blocking ClosePseudoConsole, or it can close all 3 handles like in the example above.

Long term, wezterm should use the proper ConPTY APIs of course, but short term it would be absolutely fine to cast HPCON to an array of handles. Its struct layout is part of the kernel ABI and so it won't change in any existing version and is unlikely to change any time soon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will read your message in detail and change this pr accordingly on monday when I am back in a windows box

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, because until recently you must read from the output pipe concurrently while ClosePseudoConsole is called. This is also true for the version of ConPTY that wezterm uses.

Understood, I was suspecting that, in the docs I read that is recommended to drain
communication channels in a separate thread, but I thought maybe I could get
away without creating a separate thread and keep things simpler.

I couldn't put that block after ClosePseudoConsole because that's the
function that was blocking but you solved that problem for me below.

However, starting microsoft/terminal#17704 you can do something else: You can first call the new ClosePseudoConsole and then (on the same thread; not concurrently) read from the output pipe until it is closed on you (returns an error). Basically, you can do what you wrote, but with the order flipped.

One part of me is eager to upgrade and learn about conpty and wezterm but given
that I don't know wezterm's codebase and only know about conpty what you taught
me I will leave that for a separate pr and keep this pr with the minimal patch
that solves the closing panes hanging problem.

If you don't want to upgrade ConPTY now, you can do something like this as a temporary workaround (pseudo-code; I keep forgetting what valid Rust syntax looks like lol):

fn drop(&mut self) {
    // A `HPCON` is a struct consisting of 3 HANDLEs:
    // A pipe for communicating with the PTY, a handle to keep it alive
    // until ClosePseudoConsole is called, and a process handle to the
    // underlying conhost process.
    unsafe {
        let handles = self.con as *mut [HANDLE; 3];
        for i in ..3 {
            CloseHandle(handles[i]);
            handles[i] = std::ptr::null();
        }
    }

    // read up to 1000 bytes
    while let Ok(num_byes_read) = self.output.read(&mut buffer[..]) {
        if num_byes_read == 0 {
            break;
        }
    }

    // This won't do anything but deallocate the handle.
    unsafe { (CONPTY.ClosePseudoConsole)(self.con) };
}

Thanks for the example, for this PR this will be the easiest I will just copy pasta your code and make it compile.

That aside, ReleasePseudoConsole is a new function which does the same as the unsafe code above but only for the 2nd handle (which keeps conhost alive). I've started writing documentation for it here: MicrosoftDocs/Console-Docs#323 Here's a preview of the documentation: https://github.com/MicrosoftDocs/Console-Docs/blob/dev/lhecker/24h2/docs/releasepseudoconsole.md

Ideally Wezterm should call ReleasePseudoConsole (or close the 2nd HPCON handle) right after attaching an application to ConPTY, about here: https://github.com/FrancescElies/wezterm/blob/a25e7be9bc6c68290ed465b6c1aa780cfee9b793/pty/src/win/pseudocon.rs#L189-L191

It should then stop returning a process handle from that function and not use it to track the shell/application lifetime anymore. Instead, it should read from the output pipe until the pipe has been closed on it by the PTY. If wezterm wants to kill all attached console applications prematurely (e.g. when closing the tab), it can call the upcoming non-blocking ClosePseudoConsole, or it can close all 3 handles like in the example above.

Long term, wezterm should use the proper ConPTY APIs of course, but short term it would be absolutely fine to cast HPCON to an array of handles. Its struct layout is part of the kernel ABI and so it won't change in any existing version and is unlikely to change any time soon.

Even though your explanations are very clear I will leave that for a separate
PR, I am sure if I attempt this I will misinterpret things and will need you to
hold my hand in the process.

I will try to maximize the chances of just fixing my issue first and later on
attempt that or at least create an issue linking your comment in case someone
else feels like trying the upgrade.

@FrancescElies
Copy link
Author

@RasmusN pr updated

@FrancescElies FrancescElies marked this pull request as ready for review August 19, 2024 06:09
@FrancescElies
Copy link
Author

@RasmusN did you have any issues with this build, so far using this pr today wezterm didn't hang for me anymore.

@FrancescElies FrancescElies changed the title fix: closing panes on windows sometimes hang fix(windows): closing panes sometimes hang Aug 19, 2024
@FrancescElies FrancescElies changed the title fix(windows): closing panes sometimes hang fix(windows): closing panes sometimes freezes wezterm Aug 19, 2024
@RasmusN
Copy link

RasmusN commented Aug 19, 2024

@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.

@FrancescElies
Copy link
Author

@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
Copy link

RasmusN commented Aug 19, 2024

@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:

$ cargo build --release Compiling openssl-sys v0.9.103 Compiling libz-sys v1.1.18 Compiling image v0.25.2 Compiling terminfo v0.9.0 Compiling mlua-sys v0.6.2 Compiling wezterm-input-types v0.1.0 (C:\Users\RasmusNordström\projects\wezterm\wezterm-input-types) Compiling fancy-regex v0.11.0 Compiling wezterm-bidi v0.2.3 (C:\Users\RasmusNordström\projects\wezterm\bidi) Compiling vtparse v0.6.2 (C:\Users\RasmusNordström\projects\wezterm\vtparse) Compiling same-file v1.0.6 Compiling serial-core v0.4.0 Compiling libssh2-sys v0.3.0 Compiling libssh-rs-sys v0.2.4 Compiling instant v0.1.13 Compiling fixedbitset v0.4.2 Compiling openssl v0.10.66 Compiling hex v0.4.3 Compiling memmem v0.1.1 Compiling libm v0.2.8 Compiling foreign-types-shared v0.1.1 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
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\...

@clemenscodes
Copy link

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!

@FrancescElies
Copy link
Author

FrancescElies commented Aug 21, 2024

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 StrawberryPerl/Perl-Dist-Strawberry#135 which is now solved, that kept me from building wezterm for a while.

Colleagues with special characters faced also this one fastapi/typer#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.

@FrancescElies
Copy link
Author

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.

@FrancescElies
Copy link
Author

👋 @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.

@RasmusN
Copy link

RasmusN commented Aug 26, 2024

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.

@FrancescElies
Copy link
Author

FrancescElies commented Aug 27, 2024

@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?

@RasmusN
Copy link

RasmusN commented Aug 27, 2024

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.

@RasmusN
Copy link

RasmusN commented Aug 27, 2024

I've used it the whole day, not a single freeze so far.

@@ -1,5 +1,5 @@
use crate::cmdbuilder::CommandBuilder;
use crate::win::psuedocon::PsuedoCon;
use crate::win::pseudocon::PsuedoCon;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Randomly passing by, but shouldn't you rename the PsuedoCon struct as well while you are at it ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, missed that one, addressed with the latest update

@wez
Copy link
Owner

wez commented Sep 14, 2024

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 e7fe7c0 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!

@FrancescElies
Copy link
Author

I understand, i would gladly try to upgrade conpty myself but I won’t be able to do that until April next year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[windows] wezterm hangs randomly, mostly but not exclusively, when closing panes.
6 participants