Tcl Source Code

View Ticket
Login
Ticket UUID: 858404314692d758d1aba126ac6dd0c448c1de3b
Title: Windows: after and Tcl_Sleep can sleep about 72 minutes
Type: Bug Created on: 2026-10-16 22:01:31
Submitter: serhiy.storchaka Assigned to: aku
Subsystem: 03. Timer Events Severity: Minor
Priority: 5 Medium Last modified: 2026-10-22 17:19:27
Status: Closed Closed by: serhiy.storchaka
Resolution: Fixed Closed on: 2026-10-17 07:25:45
Version: 9.0.5
Description:

In the retry loop of Tcl_Sleep() (win/tclWinNotify.c), vdelay.usec = desired.usec - now.usec is negative when the remaining time crosses a second boundary, and (unsigned long)vdelay.usec / 1000 turns it into about 4294967 ms, so SleepEx() waits about 71.6 minutes. The loop runs when SleepEx() wakes before Tcl's clock reaches the target, which happens easily on virtual machines: a 9.0.5 tclsh and its children all hung in [after 8000] for more than 10 minutes on a Windows 11 VM.

The cast came with [837dbec7cc]. 8.6 (signed arithmetic) and 9.1 (TIP 723) are not affected.

User Comments:
serhiy.storchaka added on 2026-10-16 22:03:36:

Proposed fix in branch win-sleep-negative-usec (from core-9-0-branch): compute the delay before casting it to DWORD. Tested on Windows 11 with a slowed-down Tcl clock: 9.0.5 hung in 4 of 8 runs, the fixed build in none.


jan.nijtmans added on 2026-10-17 06:51:49:

+1

Please go ahead


serhiy.storchaka added on 2026-10-17 07:25:45:

Merged into 9.0 in [19fc013bb1]. Main is not affected (TIP 723).