Welcome! Log In Create A New Profile

Advanced

Re: Sending a notification to the main nginx thread

Maxim Dounin
October 06, 2021 09:12AM
Hello!

On Tue, Oct 05, 2021 at 02:04:14PM +0000, Eran Kornblau wrote:

> Hi all,
>
> I’m planning a module in which I want to send a notification from a side thread to the main nginx thread.
> I checked the implementation of the thread pool module, and saw that it uses ngx_notify for that.
> But, checking how that function is implemented (checked epoll), I saw that it can’t really be used for any other purpose…
> If I send my function to ngx_notify, it will overwrite the thread pool handler, and can lead to race conditions…
>
> Googling for this problem, I saw this old patch –
> https://mailman.nginx.org/pipermail/nginx-devel/2016-August/008679.html
> which didn’t get any replies…
>
> Was wondering – is there some alternative solution for what I’m trying to do?
> Will you consider applying this/some other patch to address this issue?

First of all, you may want to take a look at this warning in the
development guide:

http://nginx.org/en/docs/dev/development_guide.html#threads_pitfalls

Quoting it here:

It is recommended to avoid using threads in nginx because it will definitely
break things: most nginx functions are not thread-safe. It is expected that a
thread will be executing only system calls and thread-safe library functions.
If you need to run some code that is not related to client request processing,
the proper way is to schedule a timer in the init_process module handler and
perform required actions in timer handler. Internally nginx makes use of
threads to boost IO-related operations, but this is a special case with a lot
of limitations.


--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Sending a notification to the main nginx thread

erankor 597 October 05, 2021 10:06AM

Re: Sending a notification to the main nginx thread

Maxim Dounin 234 October 06, 2021 09:12AM

RE: Sending a notification to the main nginx thread

erankor 375 October 06, 2021 03:54PM

Re: Sending a notification to the main nginx thread

Maxim Dounin 286 October 07, 2021 09:08AM

RE: Sending a notification to the main nginx thread

erankor 354 October 07, 2021 11:18AM

Re: Sending a notification to the main nginx thread

Maxim Dounin 248 October 07, 2021 01:18PM

RE: Sending a notification to the main nginx thread

erankor 350 October 07, 2021 03:48PM

Re: Sending a notification to the main nginx thread

dnj0496 310 October 07, 2021 01:28PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 152
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready