-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socket close: graceful shutdown vs. lingering (eternal TIME_WAIT issue) #14
Comments
Revisited that... first attempt to fix is partially successful (fewer TIME_WAITs now, but they are still there sporadically), must investigate deeper... test code ...proc log args {}
proc get_tw_count {port} {
regexp -all [regsub {@port} {:@port\M[^\n]+TIME_WAIT} $port] [exec netstat -n]
}
proc test {port} {
puts [string repeat -- 20]\t[get_tw_count $port]
timerate {
puts [timerate {
close [set ch [socket 127.0.0.1 $port]]
log C-closed-cli:\t$ch
} 2000 50]
after 100; puts [string repeat -- 20]\t[get_tw_count $port]
} 2000
}
proc test_server {port onConnect} {
package require Thread
thread::send -async [set th [thread::create]] [list proc log args [info body log]]
thread::send -async $th [list proc onConnect {ch args} $onConnect]
thread::send -async $th [list set port $port]
thread::send $th { set srv [socket -server onConnect $port] }
test $port
thread::send $th {close $srv; thread::release}
}
puts "================== extern (web-server) =============="
test 80
puts "================== simple-close ====================="
test_server 8055 {
log S-close-srv:\t$ch; close $ch; log S-closed:\t$ch
}
puts "================== proper-close ====================="
test_server 8055 {
chan event $ch readable [list apply {{ch} {
if {[catch {string length [read $ch 1024]} s] || $s == 0} {
log S-close-srv:\t$ch; close $ch; log S-closed:\t$ch
}
}} $ch]
} |
Fixed (well there are some TIME_WAIT still remaining sporadically, but the "flood" is completely gone)... before (not fixed, ca. 1500 handles in TIME_WAIT) ...
after (fixed, 0 handles in TIME_WAIT) ...
I'll make a small review and hereafter a PR here. |
…wn vs. lingering (eternal TIME_WAIT issue); back-ported [b960d1b71e] from tcl-repo, adjusted for IOCP, provides asynchronous close in helper thread (after completion) if pending operations available
Package seems to be affected by same issue as Tcl - [b6d0d8cc2c]:
results to this:
This test and test in next comment expecting replacement for
socket
with::iocp::inet::socket
or following inject for every interpreter (thread) used in test:May be similar fix like [b960d1b71e] or some option (like
-linger
) can be implemented to avoid such TIME-WAIT floods.Or even both, so
-linger auto
may be set as default, so decision whether lingering or graceful shutdown is expected can follow the implementation like [b960d1b71e].The text was updated successfully, but these errors were encountered: