Artifacts Associated With Ticket 0c1e91
Ticket change [86995df38f] (rid 257188) by robgcs on 2026-10-01 12:02:40:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Hello, everybody We are currently in the process of porting our application from Tcl/Tk 8.6 to 9.0. In the process, we have encountered a problem with zooming in and out within our WMS (Web Map Service) module. The error occurs under Linux (openSUSE Leap 16.0 and Debian 13) with Tcl 9.0.3 (and most likely with 9.0.4 as well), but not with Tcl 8.6.16. The source code for Tcl 9.0.3 contains the file `library/http/http.tcl`, and line 1727 reads as follows: set sock [namespace eval :: $state(openCmd)] Here, the command previously registered via `http::register` is executed. If this command, for example, executes a `vwait` (as occurs, for instance, in the `autoproxy` package [autoproxy::tls_socket]), then events are processed in the meantime and their handlers are executed. These handlers can, in turn, call `http::reset` and `http::cleanup`, so that the token (the variable `state` in ::http::OpenSocket) no longer exists after returning from line 1727. The HTTP module then terminates, for example, with the following error message, which is difficult to catch/handle: can't read "state(-keepalive)": no such element in array I have attached a small script that can be used to reproduce the error, and also a quick-and-dirty patch (see below). Kind regards, Robert #!/usr/bin/env wish package require http package require tls wm title . "Logo" wm minsize . 300 300 set waitForMe 0 proc lameTlsSocket {args} { # Let's wait a little bit vwait ::waitForMe return [tls::socket {*}$args] } http::register https 443 lameTlsSocket label .label -text "Use the keyboard or mouse to generate a series of events" -wraplength 300 pack .label -expand 1 proc getLogo {args} { .label configure -image "" if {[info exists ::currentRequest]} { # Stop current request puts "Stop current request $::currentRequest" http::reset $::currentRequest } # Start new request set ::currentRequest [http::geturl "https://thumb.wikimedia.org/wikipedia/commons/thumb/4/41/Tcl.svg/120px-Tcl.svg.png" -command displayLogo] puts "New request $::currentRequest" } bind . <MouseWheel> getLogo bind . <Button> getLogo bind . <Key> getLogo proc displayLogo {token} { if {[http::status $token] eq "ok"} { set data [http::data $token] try { image create photo logo -format png -data $data .label configure -image logo } on error {err} { puts $err } } puts "Cleanup $token" http::cleanup $token if {$token eq $::currentRequest} { unset ::currentRequest } } proc goOn {} { incr ::waitForMe after 1000 goOn } goOn ### END OF SCRIPT --- library/http/http.tcl +++ library/http/http.tcl @@ -1754,7 +1754,7 @@ dict unset socketCoEvent($state(socketinfo)) $token unset -nocomplain state(socketcoro) - if {[catch { + try { if {$state(reusing)} { # If ($state(reusing)) is true, then we do not need to create a new # socket, even if $sockOld is only a placeholder for a socket. @@ -1765,6 +1765,10 @@ ##Log pre socket opened, - token $token ##Log $state(openCmd) - token $token set sock [namespace eval :: $state(openCmd)] + if {![info exists state]} { + catch {close $sock} + return + } set state(sock) $sock # Normal return from $state(openCmd) always returns a valid socket. # A TLS proxy connection with 407 or other failure from the @@ -1791,7 +1795,7 @@ # Code above has set state(sock) $sock ConfigureNewSocket $token $sockOld $DoLater ##Log OpenSocket success $sock - token $token - } result errdict]} { + } on error {result errdict} { ##Log OpenSocket failed $result - token $token # There may be other requests in the socketPhQueue. # Prepare socketPlayCmd so that Finish will replay them. - foundin initialized to: "9.0.3"
- is_private initialized to: "0"
- login: "robgcs"
- priority initialized to: "5 Medium"
- private_contact initialized to: "46a2e3583f4f71c2c357a51bf39365bc9937aa6f"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "robgcs"
- subsystem initialized to: "29. http Package"
- title initialized to:
Problem with ::http::OpenSocket in HTTP module (library/http/http.tcl) since Tcl 9.0.x
- type initialized to: "Bug"
Ticket change [c32d9cf806] (rid 257193) by oehhar on 2026-10-01 12:51:30:
- icomment:
Hi Robert, explanation and patch looks good. You have replaced catch by try for practical reasons? Others will probably take care. I don't understand the http package so much... THanks again, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [bb354673b5] (rid 257196) by robgcs on 2026-10-01 13:27:36:
- icomment:
Hi Harald Without the try{}, the `return` statement would not have worked as intended (the `return` statement would have caused a jump to the error-handling code). Kind regards, Robert - login: "robgcs"
- mimetype: "text/plain"
- icomment:
Ticket change [1ae8f42989] (rid 258016) by serhiy.storchaka on 2026-10-14 15:15:32:
- foundin changed to: "9.0.5, 9.1.0"
- icomment:
Reproduced with 9.0.5 and 9.1 (8.6 opens the socket synchronously in <nowiki>[http::geturl]</nowiki>, so it is not affected). Besides the error after <nowiki>[http::cleanup]</nowiki> (which also leaks the new socket), a plain <nowiki>[http::reset]</nowiki> while the socket command runs the event loop is not respected: the request continues and finally gets status "ok". Proposed fix in branch [/timeline?r=http-reset-during-open|http-reset-during-open]: after the socket command returns, http::OpenSocket checks whether the request has been reset or cleaned up, and if so closes the new socket and returns. Tests http-4.17 and http-4.18.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
Ticket change [74889da32d] (rid 258242) by jan.nijtmans on 2026-10-16 13:08:05:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461330.0472870139"
- closer changed to: "jan.nijtmans"
- icomment: "Fixed in [2d6eb233b6|trunk] and core-9-0-branch"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"