Forum: NGINX Accept connections and close connection hooks in custom module

Posted by ConnorMcLaud (Guest)
on 2012-07-30 19:06
(Received via mailing list)
Hi all,

I'm currently porting Apache module to nginx and need to have
preconnection and postconnection hook for custom code.
In apache it is ap_hook_pre_connection and apr_pool_cleanup_register
calls.

Is it possible in nginx?

Thanks in advance

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,229100,229100#msg-229100
Posted by ConnorMcLaud (Guest)
on 2012-08-20 12:25
(Received via mailing list)
I think I've finally understood. There is global structure 
ngx_event_actions
with add_conn/del_conn handlers which supposed to do what I want. There 
is
only one issue (probably a bug) with add_conn handler. In version 1.2.2 
with
epoll usage handler add_conn never called. You should use add handler
instead and check incoming parameters (event = NGX_READ_EVENT, flags =
NGX_CLEAR_REQUEST). Hope it helps someone.

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,229100,229921#msg-229921
Posted by Maxim Dounin (Guest)
on 2012-08-27 14:00
(Received via mailing list)
Hello!

On Mon, Aug 20, 2012 at 06:25:09AM -0400, ConnorMcLaud wrote:

> I think I've finally understood. There is global structure ngx_event_actions
> with add_conn/del_conn handlers which supposed to do what I want. There is
> only one issue (probably a bug) with add_conn handler. In version 1.2.2 with
> epoll usage handler add_conn never called. You should use add handler
> instead and check incoming parameters (event = NGX_READ_EVENT, flags =
> NGX_CLEAR_REQUEST). Hope it helps someone.

The add_conn/del_conn handlers isn't what you want to touch from
your module, it's handlers for event modules to register
connections in an event handling machinery.  These hooks are
called not only for client connections, but e.g. for nginx own
internal connections as well, and for listening sockets also.

Moreover, nginx core is aware of aspects of various event methods
supported and might not call add_conn/del_conn even if the are
set.  The issue with epoll you've hit is just one of the cases.

Right now there is no good way to hook new accepted connections
unless you are writing your own core module which creates
listening sockets by itself.  Most recent point for correct hooks
available as of now for http modules is NGX_HTTP_POST_READ_PHASE.

Maxim Dounin
Posted by ConnorMcLaud (Guest)
on 2012-08-27 14:01
(Received via mailing list)
In fact I mostly need catch client deconnection. There is no good way 
for
that as for accepted connection, isn't it?

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,229100,229958#msg-229958
Posted by Maxim Dounin (Guest)
on 2012-09-01 17:12
(Received via mailing list)
Hello!

On Tue, Aug 21, 2012 at 10:46:32AM -0400, ConnorMcLaud wrote:

> In fact I mostly need catch client deconnection. There is no good way for
> that as for accepted connection, isn't it?

Actually there is: add a cleanup handler for a connection pool.

Maxim Dounin
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.