How to detect a client-closed connection during a write from our LDAP server?

ronnie sahlberg ronniesahlberg at gmail.com
Fri Sep 30 02:13:06 UTC 2022


On Fri, 30 Sept 2022 at 11:53, ronnie sahlberg <ronniesahlberg at gmail.com> wrote:
>
> On Fri, 30 Sept 2022 at 11:28, Andrew Bartlett via samba-technical
> <samba-technical at lists.samba.org> wrote:
> >
> > I've been trying to chase down the CPU spins reported by our users in
> > the writev() codepath from our LDAP server.
> >
> > A private mail the the strace output shows the sockets are in
> > CLOSE_WAIT state, returning EAGAIN over and over (after a call to
> > epoll() each time).  That alone would be enough to keep things
> > spinning.
> >
> > But they are being shut down, however our LDAP server won't be
> > triggering a read any time soon, it is waiting to flush the response
> > out.
> >
> > Technically even after our server OS has got the FIN, there is
> > potentially data in the read buffer (so a read() might not return 0
> > anyway), but perhaps most of the time that would be 0.
> >
> > So how can we detect this?  Can we at least put a timeout on a writev()
> > call via tsocket et al?  If so, how do we do that?
>
> Do I understand this right?
> Your process has a socket that is in CLOSE_WAIT state. When the process tries to
> writev() to this socket it gets -EAGAIN and not a more "hard" error?
>
> I wonder if getsockopt(fd, SOL_SOCKET, SO_ERROR,  could be useful here
> or would that also return EAGAIN.

And if that fails, you might be able to test it by the much messier
poll() and check for POLLIN and then read() into a buffer.
Once poll() returns POLLIN and read() returns 0 then you know the
socket is closed.
Once poll() no longer returns POLLIN then you know the socket is still
open and you will have
a mess to sort out how to "un-read()" all the bytes you read from the
socket to check if it was open or not :-(


>
>
> >
> > Mailing list threads:
> >
> > https://lists.samba.org/archive/samba/2022-September/241869.html
> > https://lists.samba.org/archive/samba/2022-September/241873.html
> >
> > Andrew Bartlett
> > --
> > Andrew Bartlett (he/him)       https://samba.org/~abartlet/
> > Samba Team Member (since 2001) https://samba.org
> > Samba Team Lead, Catalyst IT   https://catalyst.net.nz/services/samba
> >
> > Samba Development and Support, Catalyst IT - Expert Open Source
> > Solutions
> >
> >



More information about the samba-technical mailing list