Re: [PATCH] close.2: Mention a need of shutdown before closing socket

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

 



Hi Lukas

On Fri, Oct 7, 2011 at 9:09 AM, Lukas Czerner <lczerner@xxxxxxxxxx> wrote:
> On Fri, 7 Oct 2011, Michael Kerrisk wrote:
>
>> Lukas,
>>
>> On Mon, Aug 29, 2011 at 2:26 PM, Lukas Czerner <lczerner@xxxxxxxxxx> wrote:
>> > When dealing with sockets, we have to be sure that there is no recv
>> > still blocking on it on another thread, otherwise it might block forever,
>> > since no more messages will be send via the socket. We should advice to
>> > use shutdown before closing socket.
>>
>> I'm looking into this now. The picture may be more complex than this.
>> Tell me, so you have a Solaris system available for testing?
>>
>> Thanks,
>
> Hi Michael,
>
> Thanks for looking into this. Unfortunately I do not have any Solaris system
> for testing, that was a customer report. His complaint was mainly not because
> the behaviour on Linux differs, but because this was not documented anywhere.

Okay. I will see if I can find a test system somewhere. (The system I
used to use seems to have gone away.)

Just FYI: I confirmed what you are seeing, but the issue seems more
general: basically, closing a file descriptor in one thread while
reading in another thread does not cause the read operation to
terminate (it will still read data if/when it becomes available).

By the way, I'm wondering about creating a small repo of test
programs. I might like to add a modified version of your test program
to that repo. Can you put that code under a Free License and supply a
copyright?

Thanks,

Michael



>> > Signed-off-by: Lukas Czerner <lczerner@xxxxxxxxxx>
>> > ---
>> >  man2/close.2 |    7 +++++++
>> >  1 files changed, 7 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/man2/close.2 b/man2/close.2
>> > index a2a2961..02472f3 100644
>> > --- a/man2/close.2
>> > +++ b/man2/close.2
>> > @@ -114,6 +114,13 @@ other threads in the same process.
>> >  Since a file descriptor may be reused,
>> >  there are some obscure race conditions
>> >  that may cause unintended side effects.
>> > +.PP
>> > +When dealing with sockets, you have to be sure that there is no
>> > +.BR recv (2)
>> > +still blocking on it on another thread, otherwise it might block forever,
>> > +since no more messages will be send via the socket. Be sure to use
>> > +.BR shutdown (2)
>> > +to shut down all parts the connection before closing the socket.
>> >  .\" Date: Tue, 4 Sep 2007 13:57:35 +0200
>> >  .\" From: Fredrik Noring <noring@xxxxxxxxxx>
>> >  .\" One such race involves signals and ERESTARTSYS. If a file descriptor
>> > --
>> > 1.7.4.4
>> >
>> >
>>
>>
>>
>>
>
> --



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux