Skip to content

Conversation

@xal-0
Copy link
Member

@xal-0 xal-0 commented Nov 6, 2025

Wasn't sure if we could get away with deleting the uv_thread_detach, but
apparently we can. On Windows, it's definitely unsafe to keep using the thread
handle after closing it. POSIX is a little less clear about what you're allowed
to do with a pthread_t after detaching it, but the GC threads never exit
normally anyway.

Fixes #60042.

@xal-0 xal-0 requested a review from d-netto as a code owner November 6, 2025 00:42
@xal-0 xal-0 added multithreading Base.Threads and related functionality bugfix This change fixes an existing bug labels Nov 6, 2025
@Keno
Copy link
Member

Keno commented Nov 9, 2025

I agree that this fixes the issue, but it also feels like it may be a libuv bug? libuv already creates a duplicate handle for uv_thread_self if the thread was launched externally. There is something weird about this lifetime assumption. @vtjnash?

@Keno Keno requested a review from vtjnash November 9, 2025 23:34
@vtjnash
Copy link
Member

vtjnash commented Nov 10, 2025

This function is a promise to libuv that you will never run any libuv code on that thread ever again, so it is basically just use-after-free

@Keno
Copy link
Member

Keno commented Nov 10, 2025

Ok, but that seems like a big caveat missing from the documentation, because that's not how pthread works.

@Keno Keno merged commit d8b5662 into JuliaLang:master Nov 10, 2025
10 checks passed
KristofferC pushed a commit that referenced this pull request Nov 10, 2025
Wasn't sure if we could get away with deleting the `uv_thread_detach`,
but
apparently we can. On Windows, it's definitely unsafe to keep using the
thread
handle after closing it. POSIX is a little less clear about what you're
allowed
to do with a `pthread_t` after detaching it, but the GC threads never
exit
normally anyway.

Fixes #60042.

(cherry picked from commit d8b5662)
Keno added a commit to Keno/libuv-1 that referenced this pull request Nov 10, 2025
This seems like an important caveat, but was not documented.

Ref JuliaLang/julia#60056 (comment)
@xal-0 xal-0 deleted the fix-windows-profiler-deadlock branch November 10, 2025 22:50
KristofferC pushed a commit that referenced this pull request Nov 11, 2025
Wasn't sure if we could get away with deleting the `uv_thread_detach`,
but
apparently we can. On Windows, it's definitely unsafe to keep using the
thread
handle after closing it. POSIX is a little less clear about what you're
allowed
to do with a `pthread_t` after detaching it, but the GC threads never
exit
normally anyway.

Fixes #60042.

(cherry picked from commit d8b5662)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.13 bugfix This change fixes an existing bug multithreading Base.Threads and related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profiler deadlocks on Windows because of handle use-after-free

4 participants