| Ticket UUID: | b78d94c049af5090a9ef1c4aaa8059aa45b98b59 | |||
| Title: | Thread pool panics if stdin closed and IO performed in initcmd | |||
| Type: | Bug | Version: | 8.6 - Linux | |
| Submitter: | aleteoryx | Created on: | 2025-02-22 03:01:37 | |
| Subsystem: | 49. Threading | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2025-02-24 23:20:20 | |
| Resolution: | Invalid | Closed By: | sebres | |
| Closed on: | 2025-02-24 23:20:20 | |||
| Description: |
The following code panics with "Tcl_RegisterChannel: duplicate channel names". The IO call in the initcmd does not matter; I discovered the issue with a `package require` call.
```
package require Thread
close stdin
set pool [tpool::create -initcmd {
open tmpfile w
}]
tpool::post $pool {}
```
| |||
| User Comments: |
sebres added on 2025-02-24 23:20:20:
Well, it looks like this is indeed an issue of tcl (not the thread-module). Here is the experimental commit that solves the issue - [93d9a20635]. Although I'm not quite convinced with this solution. In general the usage of standard channels across threads is not well thought out in tcl-IO:
Basically the proper and consistent solution can be:
chw added on 2025-02-22 15:18:18: There's now an open ticket https://core.tcl-lang.org/thread/info/8c7d212ebece48e3 in the thread package for further discussion. chw added on 2025-02-22 14:54:15: I believe this is a real legit bug, since the Thread package still shouldn't produce a crash. The problem is, that the thread functions of both the tpool::create and thread::create command do not proper setup the TSD of the I/O subsystem before calling Tcl_CreateInterp() etc. This might be remedied by calling the Tcl_GetStdChannel() function for all standard channels before Tcl_CreateInterp(). sebres added on 2025-02-22 13:17:02: It's not a bug, it's a documented feature... If the standard channels get closed, they will be reopen by next channel open command (chan/file/pipe/socket/whatever). Just in your case the unexpected thing - you do that not from main thread (and the channel is opened not for read)... See https://stackoverflow.com/a/68869664 for more detailed answer to similar question. No idea what are you trying to do by closing of stdin, but if it is something like signal to caller EOF, you can simply reopen new (dummy) stdin implicitly after `close stdin`, for instance with `chan pipe` command. By the way, this is Tcl- not thread-repository, so basically every thread-related stuff belongs to thread-repository. | |||