Skip to content
Tcl Source Code View Ticket
Login

View Ticket

http::geturl -keepalive intermittent socketWrState errors

Closed / Fixed05b158ed56d9e68249ce6f22fe49f3133c5b98baCreated 79 days agoUpdated 21 days ago
Descriptionplain2026-09-15 16:50:16
A call like this in a polling loop occasionally errors for me:

set my_url https://example.org
::http::geturl $my_url -keepalive 1

The errorInfo isn't terribly helpful but it does look like a bug in the http package:

can't read "socketWrState(example.org:443)": no such element in array
    while executing
"::http::geturl $my_url -keepalive 1"

I'm using TclTLS 2.0.1 for https support. The same code running under Tcl 8.6 didn't have this problem. I'm happy to add code to print some more info if you can tell me what to have it look at.
Referenced by5
  • 2afc1697cbNew ticket [7c9b3f3832] New http test failures. ticket2026-11-10 16:40:31
  • 655b9df308Fix [05b158ed56] and [3764f4e81f]: http::OpenSocket opens a new connection if the persistent socket it was going to reuse has been closed in the meantime check-in2026-11-10 16:11:20
  • 98a1b78011Fix [05b158ed56] and [3764f4e81f]: http::OpenSocket opens a new connection if the persistent socket it was going to reuse has been closed in the meantime check-in2026-11-10 16:08:24
  • a623015943Ticket [3764f4e81f] http11 test suite is unreliable under load status still Open with 4 other changes ticket2026-10-16 21:36:11
  • 00a815eb5eFix [05b158ed56] and [3764f4e81f]: http::OpenSocket opens a new connection if the persistent socket it was going to reuse has been closed in the meantime (e.g. by CheckEof), instead of failing with "can't read socketWrState(...)". An empty line left after a chunked response on a persistent socket is not taken as the status line, so that the request is replayed if eof follows. check-in2026-10-16 21:34:52
jmrootplain2026-09-16 22:48:07
Here's a test program that reproduces the error on the second loop iteration for me:

package require http
set url http://ftp.fau.de/macports/
while 1 {
    if {![catch {::http::geturl $url -keepalive 1} token]} {
        if {[::http::status $token] eq "ok" && [::http::ncode $token] == 200} {
            set data [::http::data $token]
            puts "page fetched ok"
        } else {
            puts stderr "HTTP error: [::http::error $token]"
        }
        ::http::cleanup $token
    } else {
        puts stderr $::errorInfo
        puts stderr "Error: ::http::geturl returned: $token"
    }
    after 60000
}
oehharwiki2026-09-17 06:35:29

I can confirm with tcl 9.0.4 and 8.6.15 that this happens in TCL 9 and not in TCL 8.6.

Thanks for the report!

Harald

serhiy.storchakawiki2026-10-16 21:36:11

Reproduced on 9.0 and main with a local server that closes idle keep-alive connections: http::CheckEof closes the idle socket after geturl has chosen to reuse it but before http::OpenSocket runs, so the reuse path reads the removed socketWrState element. Proposed fix in branch http-keepalive-reuse-closed: OpenSocket opens a new connection in that case. Test http-4.19. It also fixes [3764f4e81f].

jan.nijtmanswiki2026-11-11 22:28:52

Merged to [trunk] and core-9-0-branch

Log in (anonymous is fine) to add a comment.