Re: How to deal with sockets when client crashes.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
> Let's say CLIENT 'C' from port 'c' tries to connect to SERVER 'S' to
> port 's':
> 'S' creates a new socket s1[s,c] in accept routine and hashes it.
> Now 'C' and 'S' happily exchange data when suddenly 'C' crashes ('S'
> doesn't know that and keeps s1 in the hash).
> Then 'C' connects (using the same port c) to 'S', again, 'S' creates
> a new socket in accept routine: s2[s,c]. But now, when they want to
> exchange data, server doesn't know to which of its sockets socket put

> the data: s1 or s2?

 If only the client process crashes (as opposed to the system itself),
new instance of the client should not be allowed to re-use the port
for some known time interval. I believe this is what TCP's TIME_WAIT 
state (and 2MSL timer) is all about.

> How should I solve this problem? Should I check in accept whether
> there is any ESTABLISHED socket with the same [s,c] and destroy it? 
> Or maybe return error from accept?

 Yes, you'll have to check for an existing connection and return error
if you find one. Of course, you also need a timeout mechanism to flush
out dead connections. This should take care of cases where the client
system itself crashes. TCP provides a keepalive timer to handle this
(AFAIK).

-Ravi.


__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux