Tcl Source Code

View Ticket
Login
Ticket UUID: 05b158ed56d9e68249ce6f22fe49f3133c5b98ba
Title: http::geturl -keepalive intermittent socketWrState errors
Type: Bug Created on: 2026-09-15 16:50:16
Submitter: jmroot Assigned to: nobody
Subsystem: 29. http Package Severity: Important
Priority: 5 Medium Last modified: 2026-10-16 21:36:11
Status: Open Closed by: nobody
Resolution: None Closed on:
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].