Hello!
On Wed, Jul 2, 2014 at 9:22 AM, jon.keys wrote:
> I'm curious if it would be possible to use cosocket API's in the log_by_lua
> context now since nginx is clearly making use of sockets for syslog support?
> I did a quick test and it doesn't appear that it is working but I'm unsure
> if that is an artificial limitation or something enforced by nginx directly.
>
As far as I can see from the code, the native syslog logging thing
introduced in nginx 1.7.1+ uses nonblocking datagram (not stream!)
sockets and it does not deal with the EAGAIN cases when the system
send buffer is full, so in such really busy cases, you *may* lose
data. For the same reason, the log phase handlers still do not really
support nonblocking I/O and cosockets cannot be used directly in
log_by_lua* (though there is a work-around for this; see below).
The lua-resty-logger-socket library
(https://github.com/cloudflare/lua-resty-logger-socket ) uses a
work-around via the ngx.timer.at() API
(https://github.com/openresty/lua-nginx-module#ngxtimerat ) where you
can use the full cosocket API in the context of the (0-delay) timer
Lua handler. For this reason, lua-resty-logger-socket can do much
better error handling for extreme cases and is more serious about log
data integrity.
Best regards,
-agentzh