[nginx] upstream keepalive recv MSG_PEEK check

Maxim Dounin mdounin at mdounin.ru
Mon Sep 28 20:13:32 UTC 2015


On Mon, Sep 28, 2015 at 12:49:33PM -0700, Tolga Ceylan wrote:

> Hi All,
> A quick code base question, regarding the close (read) handler
> in http_upstream_keepalive_module.c:
> ngx_http_upstream_keepalive_close_handler()
> has a recv() call with MSG_PEEK and if this returns NGX_EAGAIN,
> then it reschedules a read on epoll for my platform (Linux x86_64).
> My understanding is that this is a guard against spurious wake ups
> for whatever reason from epoll wait. If an actual data is received
> this is an error (since the connection is in keep alive pool and should not
> receive data from upstreams) and the connection is closed in this case.
> But if NGX_EAGAIN is detected, then there's no data and we continue
> with adding a read event handler to epoll.
> If my assumption is correct, then under what cases/circumstances do
> these spurious wake ups occur? In other words, why would the read handler
> be called if there's no data and recv() will return EAGAIN? In other words,
> in ngx_http_upstream_keepalive_close_handler, can't we skip the recv()
> check and proceed to close?
> Or do these spurious wake ups occur in non-epoll platforms?

Detailed explanation and a test case can be found here:


Maxim Dounin

More information about the nginx-devel mailing list