Date: Wed, 16 Oct 2019 13:33:32 -0400 From: Mark Johnston <markj@freebsd.org> To: Dheeraj Kandula <dkandula@gmail.com> Cc: freebsd-net@freebsd.org Subject: Re: Socket Sleep and Wakeup clarification Message-ID: <20191016173332.GF82455@raichu> In-Reply-To: <CA%2BqNgxS3V2cTQP8iFNfPT53G4VvHTi-VJBo=ZHgqjNmhBxCdNA@mail.gmail.com> References: <CA%2BqNgxS3V2cTQP8iFNfPT53G4VvHTi-VJBo=ZHgqjNmhBxCdNA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jul 31, 2019 at 04:36:08PM -0400, Dheeraj Kandula wrote: > Hi All, > I am reading through the socket code in uipc_socket.c file of FreeBSD > 12. > > The code invokes wakeup with the channel as so->so_timeo in the following > functions: > soisconnected > soisdisconnected > soisdisconnecting and > soshutdown > > The callers of soconnect invoke sleep so that the thread that invokes > soconnect wakes up when the TCP 3 way handshake is done. The soconnect in > kernel returns immediately unlike user space connect which sleeps. > > I also see tsleep in soclose when the socket's state is SS_ISCONNECTED. > > My questions: > 1. Is it possible to close a socket when the application is sleeping > after the application invokes soconnect. Basically I am trying to figure > out how multiple threads can access the same socket for soconnect and > soclose to happen at the same time. I don't see any particular synchronization between soclose() and the sleep you are referring to, so there might be a bug here. In particular, I would expect soclose() on a connecting socket to wake up sleepers, but I cannot see how that happens. > 2. soshutdown also invokes wakeup. This wakeup again corresponds to > the sleep by soconnect. Isn't it? How can we have two threads accessing the > same socket with one thread sleeping on a socket for the soconnect, while > another shuts down the same socket in either the RD or WR or RW direction. Yes, wakeup(&so->so_timeo) should be called whenever the connection state of a socket changes.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20191016173332.GF82455>