On 14/12/2025 07:39, Takashi Yano via Cygwin wrote:
On Sun, 14 Dec 2025 16:26:37 +0900
Takashi Yano via Cygwin <[email protected]> wrote:

Recently, I have concerned that testsuite winsup.api/pthread/cancel2 fails
consistently.

https://github.com/cygwin/cygwin/actions/runs/19926408142/job/57127200619

Thanks very much for looking into this!

I have the vague idea that this problem started showing up (more?) when the CI VM was upgraded from Windows Server 2022 to Windows Server 2025, but I guess that's maybe just timings...


I'm not sure why this happens, but it also falis in my local environment.
I looked into this issue a bit, and found that access violation happnes
in CloseHandle() in _cygtls::remove().

And I am also not sure why at all, cancel2 works if CloseHandle()'s are
replaced with NtClose() as follows.

I think this is just the difference between the two calls: CloseHandle generates an exception whereas NtClose returns an error code if the handle is invalid.

Doesn't really explain whats wrong with the handle, though.


diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
index 13d133f47..249c8cb18 100644
--- a/winsup/cygwin/cygtls.cc
+++ b/winsup/cygwin/cygtls.cc
@@ -118,7 +118,7 @@ _cygtls::remove (DWORD wait)
      {
        HANDLE h = signal_arrived;
        signal_arrived = NULL;
-      CloseHandle (h);
+      NtClose (h);
      }
if (locals.drivemappings)
@@ -148,7 +148,7 @@ _cygtls::remove (DWORD wait)
    if (mutex)
      {
        ReleaseMutex (mutex);
-      CloseHandle (mutex);
+      NtClose (mutex);
      }
  }
Any idea?

I forgot to mention that the thread crashes when canceled with
PTHREAD_CANCEL_ASYNCHRONOUS.

PTHREAD_CANCEL_DEFERRED works without the problem.

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to