Tcl Source Code

View Ticket
Login
2026-11-11
22:28 • Closed ticket [05b158ed56]: http::geturl -keepalive intermittent socketWrState e... artifact: 35ab351019 user: jan.nijtmans
2026-11-10
16:40 • New ticket [7c9b3f3832] New http test failures. artifact: 2afc1697cb user: dgp
16:11
Fix [05b158ed56] and [3764f4e81f]: http::OpenSocket opens a new connection if the persistent socket ... check-in: 655b9df308 user: jan.nijtmans tags: core-9-0-branch
16:08
Fix [05b158ed56] and [3764f4e81f]: http::OpenSocket opens a new connection if the persistent socket ... check-in: 98a1b78011 user: jan.nijtmans tags: trunk, main
2026-10-16
21:36 • Ticket [3764f4e81f] http11 test suite is unreliable under load status still ... artifact: a623015943 user: serhiy.storchaka
21:36 • Ticket [05b158ed56] http::geturl -keepalive intermittent socketWrState errors</i... artifact: a07f327187 user: serhiy.storchaka
21:34
Fix [05b158ed56] and [3764f4e81f]: http::OpenSocket opens a new connection if the persistent socket ... closed check-in: 00a815eb5e user: serhiy.storchaka tags: http-keepalive-reuse-closed
2026-09-17
06:35 • Ticket [05b158ed56] http::geturl -keepalive intermittent socketWrState errors</i... artifact: c785a96d0c user: oehhar
2026-09-16
22:48 • Ticket [05b158ed56]: 3 changes artifact: 0239461772 user: jmroot
2026-09-15
16:50 • New ticket [05b158ed56]. artifact: c74c94a144 user: jmroot

Ticket UUID: 05b158ed56d9e68249ce6f22fe49f3133c5b98ba
Title: http::geturl -keepalive intermittent socketWrState errors
Type: Bug Created on: 2026-09-15 16:50:16
Submitter: jmroot Assigned to: jan.nijtmans
Subsystem: 29. http Package Severity: Important
Priority: 5 Medium Last modified: 2026-11-11 22:28:52
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2026-11-11 22:28:52
Version: 9.0.5, 9.1.0
Description:
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.
User Comments:
jmroot added on 2026-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
}

oehhar added on 2026-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.storchaka added on 2026-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.nijtmans added on 2026-11-11 22:28:52:

Merged to [98a1b78011|trunk] and core-9-0-branch