Overview
| Artifact ID: | effa6f3340eddbd5ec181ed2993009521fcfe4ac |
|---|---|
| Ticket: | 6ca52aec14e0b33543d3cd9895f060b852ac4dbc
HTTP package: Memory leak if client requests "Connection: close" but server responses with "Connection: keep-alive" |
| User & Date: | aspect on 2015-07-20 04:15:57 |
Changes
- icomment:
The following attempts to test more concisely: ---- package require http #source patch.tcl package require coroutine proc go {args} { tailcall coroutine ::goro#[llength [info commands ::goro#*]] {*}$args } proc accept {chan host port} { fconfigure $chan -blocking 0 -buffering none fileevent $chan readable [info coroutine] catch { while {![eof $chan]} { while {[coroutine::util gets $chan header] > 0} { # discard headers } foreach line { "HTTP/1.1 200 OK" "Connection: keep-alive" "Content-length: 15" "" "<html></html>" } { puts $chan $line } } } puts "$chan returning" catch {close $chan} } set port 8080 while {[catch {socket -server {go accept} 8080} server]} { incr port } puts "listening on $port" set before [list [info vars ::http::*] [chan names]] set tok [::http::geturl http://localhost:$port/c] ::http::cleanup $tok update ;# allow events to complete set after [list [info vars ::http::*] [chan names]] if {$before eq $after} {} else { puts "ERROR: before $before" puts "ERROR: after $after" } ---- A possible fix appears to be in ::http::Finish, checking that state(-keepalive) exists and is true before testing state(connection): ---- --- library/http/http.tcl 2015-07-02 13:15:03.723694211 +1000 +++ library/http/http.tcl.patched 2015-07-20 14:13:43.063724688 +1000 @@ -197,9 +197,10 @@ set state(error) [list $errormsg $errorInfo $errorCode] set state(status) "error" } - if { - ($state(status) eq "timeout") || ($state(status) eq "error") || - ([info exists state(connection)] && ($state(connection) eq "close")) + if { ($state(status) eq "timeout") + || ($state(status) eq "error") + || ([info exists state(-keepalive)] && !$state(-keepalive)) + || ([info exists state(connection)] && ($state(connection) eq "close")) } { CloseSocket $state(sock) $token } ---- - login: "aspect"
- mimetype: "text/plain"