* Socket hangs in read() when putting interface down
@ 2007-06-05 15:11 chris schlund
2007-06-05 17:41 ` Rick Jones
0 siblings, 1 reply; 3+ messages in thread
From: chris schlund @ 2007-06-05 15:11 UTC (permalink / raw)
To: netdev
Using read() on a socket(AF_INET, SOCK_STREAM) connected via any network
interface (e.g eth0) and putting this interface down (ifconfig) while
the socket is in read() produces a hanger (the read() will not return
anymore).
Even if I install sigaction signal handler I got no signal when the
interface is removed.
This may be ok on a major interface like eth0 but it is a problem when
using a ppp interface via GSM data or GPRS connection.
Killing the pppd while the socket waits in read() produces the same
behaviour. Also a broken connection looks the same.
It is reproducable on several 2.6 kernel versions including the lastest
stable 2.6.21.
On my understanding "ifconfig down" should lead into a read() error.
Unfortunately I am not very familiar with in-depth kernel programming
and I am still wondering about the magic inside the kernel:
ifconfig -> net/dev.c:dev_close() notifies a call chain which probably
could/should handle this.
But I miss the dependency to net/ipv4/tcp.c: tcp_recvmsg() function.
This is where I think my receive is blocking.
Can someone give me a hint where to look?
Thanks and kind regards
Chris
p.s.
This happens only, when socket is in blocking mode.
I am using a simple example like:
s = socket();
connect(s);
while(){
read(s)
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Socket hangs in read() when putting interface down
2007-06-05 15:11 Socket hangs in read() when putting interface down chris schlund
@ 2007-06-05 17:41 ` Rick Jones
2007-06-06 13:55 ` chris schlund
0 siblings, 1 reply; 3+ messages in thread
From: Rick Jones @ 2007-06-05 17:41 UTC (permalink / raw)
To: chris schlund; +Cc: netdev
chris schlund wrote:
> Using read() on a socket(AF_INET, SOCK_STREAM) connected via any network
> interface (e.g eth0) and putting this interface down (ifconfig) while
> the socket is in read() produces a hanger (the read() will not return
> anymore).
> Even if I install sigaction signal handler I got no signal when the
> interface is removed.
I'd not think there was a direct tie-in between an application signal
handler and an interface being downed.
> This may be ok on a major interface like eth0 but it is a problem when
> using a ppp interface via GSM data or GPRS connection.
> Killing the pppd while the socket waits in read() produces the same
> behaviour. Also a broken connection looks the same.
> It is reproducable on several 2.6 kernel versions including the lastest
> stable 2.6.21.
>
> On my understanding "ifconfig down" should lead into a read() error.
Why? Can't traffic for the endpoint arrive via some other interface on
the system? I would think that getting out of a blocking read()
requires the application to either have a timer running (and so get out
of read() with EINTR) or to have keepalives enabled on the TCP
connection (I'm assuming TCP for an AF_INET, SOCK_STREAM although I
suppose it could be SCTP)
rick jones
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Socket hangs in read() when putting interface down
2007-06-05 17:41 ` Rick Jones
@ 2007-06-06 13:55 ` chris schlund
0 siblings, 0 replies; 3+ messages in thread
From: chris schlund @ 2007-06-06 13:55 UTC (permalink / raw)
To: Rick Jones; +Cc: netdev
>> This may be ok on a major interface like eth0 but it is a problem when
>> using a ppp interface via GSM data or GPRS connection.
>> Killing the pppd while the socket waits in read() produces the same
>> behaviour. Also a broken connection looks the same.
>> It is reproducable on several 2.6 kernel versions including the lastest
>> stable 2.6.21.
>>
>> On my understanding "ifconfig down" should lead into a read() error.
>
> Why? Can't traffic for the endpoint arrive via some other interface on
> the system? I would think that getting out of a blocking read()
> requires the application to either have a timer running (and so get out
> of read() with EINTR) or to have keepalives enabled on the TCP
> connection (I'm assuming TCP for an AF_INET, SOCK_STREAM although I
> suppose it could be SCTP)
>
> rick jones
Of course, you are right.
I am so focused to my small embedded world, that I simply have forgotten
how IP-traffic works in big systems (to clarify my first post: I'm using
TCP).
Your hint with the self produced signal to get out of read() was very
helpful for me. Thats what I was missing.
I also learned another think, while reading the list FAQ:
PEBCAC (=Problem exists between chair and computer)
Obviously, thats what best described me!
Thank you very much!
Chris Schlund
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-06-06 13:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-05 15:11 Socket hangs in read() when putting interface down chris schlund
2007-06-05 17:41 ` Rick Jones
2007-06-06 13:55 ` chris schlund
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).