Behavior of nginx on Allocation Failure
mdounin at mdounin.ru
Thu Jun 16 00:29:06 UTC 2022
On Tue, Jun 14, 2022 at 09:11:32PM -0700, Colin wrote:
> I'm interested in how nginx performs when close to/at memory limits, but
> haven't been able to find answers to a couple of things. Mainly: Does nginx
> usually treat allocation failures as recoverable, or fatal? I know
> ngx_alloc fires an emergency-level error on failure, but I'm curious about
> how nginx usually behaves afterwards.
> More generally, does nginx make any guarantees about behavior when
> allocations fail? I've looked at the memory management API but if I've
> missed any other documentation that answers these questions, feel free to
> just link me to it.
In nginx, allocation errors are properly handled according to the
particular place where the error happens. For example, if an
error happens during nginx startup - it is not possible to do
anything, so nginx will simply exit with an error. If an error
happens while handling a request, nginx will respond with error
500 (Internal Server Error) if possible and close the connection.
That is, as long as nginx is started, it is expected to work even
if some memory allocations fail (though will drop some requests /
Note though that proper handling might not apply to 3rd party
libraries being used. For example, Perl calls abort() on
allocation failures, so one certainly shouldn't rely on nginx with
embedded Perl being used in memory-constrained environments.
More information about the nginx