[nginx] upstream keepalive recv MSG_PEEK check

Tolga Ceylan tolga.ceylan at gmail.com
Mon Sep 28 19:49:33 UTC 2015

Hi All,

A quick code base question, regarding the close (read) handler
in http_upstream_keepalive_module.c:


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?

Tolga Ceylan

More information about the nginx-devel mailing list