Skip to content
Tcl Source Code History Of Ticket f10d91c2
Login

History Of Ticket f10d91c2

Artifacts Associated With Ticket f10d91c2

  1. Ticket change [61e1b753b7] (rid 254836) by juliannoble2 on 2026-07-12 03:30:07:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      process orphaned by console-host death busy-loops two threads indefinitely.
      
      This is a placeholder ticket because CDN gates aggressively.
      Unclear what text in here triggers it.
      Backchannel for ticket details?
      
    5. foundin initialized to: "9"
    6. is_private initialized to: "0"
    7. login: "juliannoble2"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "957fdfcd8744611e3fe1f4896c7538b1d9bf47b2"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "juliannoble2"
    14. subsystem initialized to: "02. Event Loops"
    15. title initialized to: "dead-console busy-loop in tclWinConsole.c"
    16. type initialized to: "Bug"
  2. Ticket change [463f3f1cb6] (rid 254837) by juliannoble2 on 2026-07-12 04:01:53:

    1. icomment:
      My failed initial ticket submission was clearly marked described as having been generated by use of Fable 5 - with my own preamble.
      
      I mentioned that it should be taken with a grain of salt as to whether this is triggered in real-world application use versus the llm generated scratch scripts and testing harnesses that caught this.
      
      I was able to reproduce the effect using the generated repro powershell scripts and noticed increased cpu use and fan spinups.
      
      First part of report here. I've ommitted the rest under the guess that CDN was triggered by code samples rather than detecting AI content.
      
      llm was pointed at up to date tcl source and did a fairly full analysis with suggestions.
      
      Ping me for more if it seems interesting.
      
      ------------------------------------------------------
      
      
      **Component:** win/tclWinConsole.c (channel driver)
      **Versions affected:** verified 9.0.2 and 9.0.3 on Windows 11 (build 26200); the defective
      code paths are unchanged in 9.1b1 sources. Tcl 8.6 is not affected (pre-rewrite console
      driver; different mechanism).
      **Severity:** Serious. Each occurrence leaves a near-invisible orphan burning ~1-2 cores
      forever, and occurrences accumulate: nothing ever reaps them, so every console-host death
      against a fileevent-reading tclsh adds one. Eight concurrent orphans produced an audible
      thermal/fan response on the test workstation while still showing nothing conspicuous in
      Task Manager (see Observability).
      
      ## Summary
      
      When the console *server* (conhost.exe) serving a Tcl 9 process dies without the client
      being terminated, a script with a `chan event stdin readable` handler is never notified:
      the driver detects the error internally, but the event it queues for the interp thread is
      discarded before `Tcl_NotifyChannel`, so no readable event, no EOF, no read error ever
      reaches script level. Meanwhile the driver's console reader thread busy-loops on the
      persistent error with no wait, and its continuous watcher-nudging keeps the interp
      thread's event loop cycling at zero block time. The process cannot even implement its own
      defence via fileevents - only a poll (see Workaround) can see the condition.
      
      ## Real-world triggers (legitimate application scenarios)
      
      The reproduction below force-kills a conhost to make the trigger deterministic, but the
      same client-side state - console server gone, client alive - arises in ordinary use.
      Exposed application profile: any long-running Tcl program that reads console stdin via a
      fileevent - a REPL, a monitor accepting operator commands, a server with console control
      input - since the trigger is entirely outside the application's control:
      
      - **A user kills a hung console window via Task Manager.** Killing "Console Window Host"
        (conhost.exe) is common folk-advice for a stuck window; TerminateProcess delivers no
        CTRL_CLOSE_EVENT, so the client survives against a dead console. (Identical mechanism
        to the scripted repro - verified.)
      - **conhost.exe crashes.** The host is an ordinary user-mode process; when it dies of its
        own bug the client is orphaned exactly as above.
      - **A terminal emulator crashes.** A clean close runs ConPTY/tab teardown that terminates
        the client tree, but a *crashed* terminal (Windows Terminal or third-party) never runs
        that cleanup; its console server goes away ungracefully. (Plausible-by-mechanism;
        untested here - the classic-conhost case is the verified repro.)
      - **Automation/CI harnesses that kill their console host.** A harness that launches work
        under a hidden console (Start-Process -WindowStyle Hidden, scheduled tasks, agent
        runners) and later "cleans up" by killing the launcher or host process - without a job
        object that covers the clients - leaves the worker tclsh orphaned. This is how the bug
        was first hit in production use: an interactive shell under a hidden console outlived
        its host and was found 37 minutes later with ~1550 cpu-seconds accumulated, discovered
        only because it polluted a test harness's process-liveness checks.
      - **Session teardown edge cases.** Any path where the session infrastructure tears down
        the console host before (or without) terminating its clients produces the same state.
      
      In every case the failure compounds: each event adds one immortal spinner, and the
      Observability section explains why nobody notices them.
      
      <elided>
      
    2. login: "juliannoble2"
    3. mimetype: "text/plain"
  3. Ticket change [5af4587dbf] (rid 254847) by apnadkarni on 2026-07-12 11:26:40:

    1. icomment:
      Sounds like something that should be fixed. Since you cannot seem to post the script here, could you post it in some pastebin? So I can verify once it's fixed?
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  4. Ticket change [5648014d21] (rid 254848) by apnadkarni on 2026-07-12 12:33:34:

    1. assignee changed to: "apnadkarni"
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  5. Ticket change [63eea7d756] (rid 254858) by juliannoble2 on 2026-07-13 01:43:41:

    1. icomment: "full Fable 5 text at: http://paste.tclers.tk/6226"
    2. login: "juliannoble2"
    3. mimetype: "text/plain"
  6. Ticket change [3be3b1acfe] (rid 254859) by apnadkarni on 2026-07-13 02:54:01:

    1. icomment:
      Thanks for the paste. I reached pretty much an identical conclusion inspecting the code yesterday. I was able to manually trigger the condition by killing from twapi.
      
      Actually, quite impressed with the diagnosis from Fable. I'm now officially redundant :-)
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  7. Ticket change [2ff1396273] (rid 254863) by apnadkarni on 2026-07-13 07:59:33:

    1. icomment:
      Proposed fix is in [bug-f10d91c2] branch. However, note that with the fix in place, the process still does not exit though CPU usage is 0. This is by intent as it is not clear (at the driver level) whether process should exit on stdin closure, and secondly, whether errors should be treated as eof.
      
      IMO, it is up to the stdin file event handler to catch the error that will be generated on the read in the event callback and take appropriate action (exit or whatever.)
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  8. Ticket change [e618e5975f] (rid 254924) by apnadkarni on 2026-07-14 16:28:15:

    1. closedate changed to: "2461236.186292477"
    2. closer changed to: "apnadkarni"
    3. icomment: "Fixed in [49925e3365]"
    4. login: "apnadkarni"
    5. mimetype: "text/x-fossil-plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
  9. Ticket change [e3a7011bff] (rid 256483) by sebres on 2026-09-18 17:52:23:

    1. closedate changed to: "2461302.2447209489"
    2. closer changed to: "sebres"
    3. icomment:
      I don't think it is good idea to cover tcl-tests with ps scripts (cannot it be scripted in tcl?)...<br/>
      Let alone, it is disabled by default per policies to invoke ps-scripts (at least from temp-folders and/or unsigned), and there are people (like me) which don't allow this intentionally. Not to mention rude corporate policies.
      
      Then you'd see something like this:
      <code><pre style="margin-left:15pt">
      ==== console-bug-f10d91c2 Test termination of console process with extreme prejudice FAILED
      ==== Contents of test case:
          exec {*}[auto_execok powershell] -File $psScript
      ---- Result was:
      File T:\Temp\bug-f10d91.ps1 cannot be loaded because running scripts is disabled on this system.
      For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
          + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : UnauthorizedAccess
      ---- Result should have been (glob matching):
      *tclsh terminated*readable fired*exiting*
      ==== console-bug-f10d91c2 FAILED
      </pre></code>
      
      I fixed it in [6128e26dc47a54bd] by skipping the test in case of policy violation, but...<br/>
      However it "works" for me now, I didn't test it on machine where starting of such ps-scripts is allowed, so please test it.
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"