<div dir="ltr">I haven't played with them myself, but have considered sub-requests? Since your are using a library with its own event-loop, perhaps it's best to run it in its own process and use nginx sub-requests to bridge the two processes? Seems doable.<div><a href="https://nginx.org/en/docs/dev/development_guide.html#http_subrequests">https://nginx.org/en/docs/dev/development_guide.html#http_subrequests</a></div><div><br></div><div>Dk.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 6, 2021 at 12:53 PM Eran Kornblau <<a href="mailto:eran.kornblau@kaltura.com">eran.kornblau@kaltura.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">> <br>
> -----Original Message-----<br>
> From: nginx-devel <<a href="mailto:nginx-devel-bounces@nginx.org" target="_blank">nginx-devel-bounces@nginx.org</a>> On Behalf Of Maxim Dounin<br>
> Sent: Wednesday, 6 October 2021 16:12<br>
> To: <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> Subject: Re: Sending a notification to the main nginx thread<br>
> <br>
> Hello!<br>
> <br>
> First of all, you may want to take a look at this warning in the development guide:<br>
> <br>
> <a href="https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnginx.org%2Fen%2Fdocs%2Fdev%2Fdevelopment_guide.html%23threads_pitfalls&data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285308685%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=%2BiDgCqNY6Wtl0elz%2FYAG7UvdOmoW%2BsZg9v0i5Oicc%2FY%3D&reserved=0" rel="noreferrer" target="_blank">https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnginx.org%2Fen%2Fdocs%2Fdev%2Fdevelopment_guide.html%23threads_pitfalls&data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285308685%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=%2BiDgCqNY6Wtl0elz%2FYAG7UvdOmoW%2BsZg9v0i5Oicc%2FY%3D&reserved=0</a><br>
> <br>
> Quoting it here:<br>
> <br>
> 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.<br>
> 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.<br>
> <br>
Thanks Maxim, I completely get that, that is the reason I was looking for way to send a notification to the main thread, and didn't just try to call nginx functions from some other thread.<br>
In my case, I need to integrate with some 3rd party library that has its own event loop, it would require significant changes to the library to make it run inside nginx's event loop...<br>
So, my plan is to run it on a side thread, and send notifications between the threads, which would trigger some handler on the main thread whenever new data arrives.<br>
I can use ngx_notify for this, but if someone will use the module and also nginx's thread pool or some 3rd party module that uses ngx_notify, it will break.<br>
I think I can live with that, but would be nice to have a solution that is complete.<br>
<br>
Eran<br>
<br>
> <br>
> --<br>
> Maxim Dounin<br>
> <a href="https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmdounin.ru%2F&data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285318679%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=j6ifgLEZxh6B60ZP2wGOoJMnb1JnaVig3Ja26LNoMk0%3D&reserved=0" rel="noreferrer" target="_blank">https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmdounin.ru%2F&data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285318679%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=j6ifgLEZxh6B60ZP2wGOoJMnb1JnaVig3Ja26LNoMk0%3D&reserved=0</a><br>
> _______________________________________________<br>
> nginx-devel mailing list<br>
> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> <a href="https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmailman.nginx.org%2Fmailman%2Flistinfo%2Fnginx-devel&data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285318679%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=dOXGqrvoFn8AnO1CGa67SCgmoiqIUdoNU8Aw9t6xGcA%3D&reserved=0" rel="noreferrer" target="_blank">https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmailman.nginx.org%2Fmailman%2Flistinfo%2Fnginx-devel&data=04%7C01%7C%7Cd0de648d5c294e07aac008d988cae55b%7C0c503748de3f4e2597e26819d53a42b6%7C1%7C1%7C637691227285318679%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=dOXGqrvoFn8AnO1CGa67SCgmoiqIUdoNU8Aw9t6xGcA%3D&reserved=0</a><br>
><br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div>