SourceForge has been redesigned. Learn more.

#480 socket writes hanging if endpoint can't be reached

obsolete: 8.2.2

OriginalBugID: 3841 Bug
Version: 8.2.2
SubmitDate: '1999-12-10'
LastModified: '2000-04-19'
Severity: SER
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
OS: Solaris
OSVersion: Solaris 2.7
Machine: UE2 UE450
FixedDate: '2000-10-25'
ClosedDate: '2000-04-19'

Christian Williams

we use a Tcl-based chat server on our web site; every time a client becomes
unreachable (i.e., its computer crashes, goes offline, etc), the whole server
freezes up for as much as 60 seconds, while Unix decides that the connection
is dead and returns an error on the send(). obviously this isn't a great user
experience, and is our #1 complaint from our users.

apart from this problem, Tcl works great as a server of this sort.

run this script from one host:
proc run { sock args } {
puts "Got connection... hit return to write"
gets stdin
set x 0
while {$x < 10000} {
puts -nonewline "\r$x bytes"; flush stdout
puts -nonewline $sock "."; flush $sock
incr x
puts ""; exit

socket -server run 6666
vwait forever

on another host, connect to that port:
telnet hosta 6666

now unplug the network connection of the second host, and hit
return on the first. the script will output data until it fills Unix's
send buffer, then block in the puts. this behaviour is the same
no matter what the socket's fconfigure options are.

send(4, " .", 1, 0) = 1
write(1, "\r 8 1 9 2 b y t e s", 11) = 11
send(4, " .", 1, 0) = 1
write(1, "\r 8 1 9 3 b y t e s", 11) = 11
send(4, " .", 1, 0) (sleeping...)

the fblocked command should indicate whether a puts will actually block,
or there should be a configurable buffer size for writes,
or Tcl should return an error,
or ANYTHING but blocking! ; )

The user mentions fblocked, but I don't see it used. In fact,
it looks like this might all be cleared up if the user were
to use non-blocking sockets throughout and base it all on
fileevents. Unless that case also hangs (which isn't specified).
-- 04/19/2000 hobbs


  • Brent B. Welch

    Brent B. Welch - 2000-10-26
    • priority: 5 --> 2
    • status: open --> closed-fixed
  • Don Porter

    Don Porter - 2001-03-31
    • labels: 104250 --> 27. Channel Types