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

ronnie sahlberg ronniesahlberg at
Fri Sep 30 01:53:41 UTC 2022

On Fri, 30 Sept 2022 at 11:28, Andrew Bartlett via samba-technical
<samba-technical at> 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.

> Mailing list threads:
> Andrew Bartlett
> --
> Andrew Bartlett (he/him)
> Samba Team Member (since 2001)
> Samba Team Lead, Catalyst IT
> Samba Development and Support, Catalyst IT - Expert Open Source
> Solutions

More information about the samba-technical mailing list