Opened 17 months ago

Last modified 4 months ago

#320 assigned enhancement

nginx should reliably check client connection close with pending data

Reported by: Sergey Kandaurov Owned by: Valentin V. Bartenev
Priority: minor Milestone:
Component: nginx-core Version: 1.3.x
Keywords: Cc:
Sensitive: no
uname -a:
nginx -V: n/a

Description (last modified by Maxim Dounin)

To detect if a connection was closed by a client, nginx uses:

  • A EV_EOF flag as reported by kqueue. This only works if you use kqueue, i.e. on FreeBSD and friends.
  • The recv(MSG_PEEK) call to test a case when connection was closed. This works on all platforms, but only if there are no pending data.

Most notably, this doesn't cover Linux and SSL connections, which are usually closed with pending data (a shutdown alert). To improve things, the following should be implemented (in no particular order):

  • SSL_peek() for SSL connections instead of recv(MSG_PEEK), likely with additional c->peek() call.
  • Support for EPOLLRDHUP, which is believed to be close to EV_EOF provided by kqueue.

References:
http://mailman.nginx.org/pipermail/nginx/2011-June/027669.html
http://mailman.nginx.org/pipermail/nginx/2011-November/030614.html
http://mailman.nginx.org/pipermail/nginx/2013-March/038119.html

Change History (7)

comment:1 Changed 17 months ago by Maxim Dounin

  • Description modified (diff)

comment:2 Changed 17 months ago by Valentin V. Bartenev

  • Owner set to vbart
  • Status changed from new to assigned

comment:3 Changed 10 months ago by Valentin Bartenev <vbart@…>

In 36b58ddb566d87d0a8b7dd81d633d5e4b0f54bca/nginx:

Events: support for EPOLLRDHUP (ticket #320).

Since Linux 2.6.17, epoll is able to report about peer half-closed connection
using special EPOLLRDHUP flag on a read event.

comment:4 Changed 10 months ago by Valentin Bartenev <vbart@…>

In 46bdbca10dfc92b0123e9f0aa657ab367e56e33c/nginx:

Upstream: use EPOLLRDHUP to check broken connections (ticket #320).

This allows to detect client connection close with pending data on Linux
while processing upstream.

comment:5 Changed 10 months ago by Valentin Bartenev <vbart@…>

In ef3d094bb6d351d790488e3ce222ea193903fbf2/nginx:

Use EPOLLRDHUP in ngx_http_test_reading() (ticket #320).

This allows to detect client connection close with pending data when
the ngx_http_test_reading() request event handler is set.

comment:6 follow-up: Changed 4 months ago by Maxim Dounin

Shouldn't we close this ticket? Valentin?

comment:7 in reply to: ↑ 6 Changed 4 months ago by Valentin V. Bartenev

Replying to Maxim Dounin <mdounin@mdounin.ru>:

Shouldn't we close this ticket? Valentin?

I don't think so. We still lack of the SSL_peek() support.

Note: See TracTickets for help on using tickets.