summaryrefslogtreecommitdiffhomepage
path: root/src/event/ngx_event.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-01-10QUIC: automatically add and never delete stream events.Roman Arutyunyan1-2/+2
Previously, stream events were added and deleted by ngx_handle_read_event() and ngx_handle_write_event() in a way similar to level-triggered events. However, QUIC stream events are effectively edge-triggered and can stay active all time. Moreover, the events are now active since the moment a stream is created.
2022-12-15Merged with the default branch.Sergey Kandaurov1-2/+7
2022-11-23Fixed segfault when switching off master process during upgrade.Maxim Dounin1-1/+3
Binary upgrades are not supported without master process, but it is, however, possible, that nginx running with master process is asked to upgrade binary, and the configuration file as available on disk at this time includes "master_process off;". If this happens, listening sockets inherited from the previous binary will have ls[i].previous set. But the old cycle on initial process startup, including startup after binary upgrade, is destroyed by ngx_init_cycle() once configuration parsing is complete. As a result, an attempt to dereference ls[i].previous in ngx_event_process_init() accesses already freed memory. Fix is to avoid looking into ls[i].previous if the old cycle is already freed. With this change it is also no longer needed to clear ls[i].previous in worker processes, so the relevant code was removed.
2022-11-23Disabled cloning of sockets without master process (ticket #2403).Maxim Dounin1-1/+4
Cloning of listening sockets for each worker process does not make sense when working without master process, and causes some of the connections not to be accepted if worker_processes is set to more than one and there are listening sockets configured with the reuseport flag. Fix is to disable cloning when master process is disabled.
2022-04-20QUIC: separate UDP framework for QUIC.Roman Arutyunyan1-2/+10
Previously, QUIC used the existing UDP framework, which was created for UDP in Stream. However the way QUIC connections are created and looked up is different from the way UDP connections in Stream are created and looked up. Now these two implementations are decoupled.
2022-01-25Merged with the default branch.Sergey Kandaurov1-0/+5
2022-01-13QUIC: removed ngx_send_lowat() check for QUIC connections.Sergey Kandaurov1-6/+0
After 9ae239d2547d, ngx_quic_handle_write_event() no longer runs into ngx_send_lowat() for QUIC connections, so the check became excessive. It is assumed that external modules operating with SO_SNDLOWAT (I'm not aware of any) should do this check on their own.
2021-12-30Events: fixed balancing between workers with EPOLLEXCLUSIVE.Maxim Dounin1-0/+5
Linux with EPOLLEXCLUSIVE usually notifies only the process which was first to add the listening socket to the epoll instance. As a result most of the connections are handled by the first worker process (ticket #2285). To fix this, we re-add the socket periodically, so other workers will get a chance to accept connections.
2021-09-09QUIC: separate event handling functions.Roman Arutyunyan1-25/+7
The functions ngx_quic_handle_read_event() and ngx_quic_handle_write_event() are added. Previously this code was a part of ngx_handle_read_event() and ngx_handle_write_event(). The change simplifies ngx_handle_read_event() and ngx_handle_write_event() by moving QUIC-related code to a QUIC source file.
2021-07-15Merged with the default branch.Sergey Kandaurov1-10/+13
2021-05-31Core: disabled cloning sockets when testing config (ticket #2188).Maxim Dounin1-10/+13
Since we anyway do not set SO_REUSEPORT when testing configuration (see ecb5cd305b06), trying to open additional sockets does not make much sense, as all these additional sockets are expected to result in EADDRINUSE errors from bind(). On the other hand, there are reports that trying to open these sockets takes significant time under load: total configuration testing time greater than 15s was observed in ticket #2188, compared to less than 1s without load. With this change, no additional sockets are opened during testing configuration.
2021-03-26Events: fixed expiration of timers in the past.Maxim Dounin1-3/+1
If, at the start of an event loop iteration, there are any timers in the past (including timers expiring now), the ngx_process_events() function is called with zero timeout, and returns immediately even if there are no events. But the following code only calls ngx_event_expire_timers() if time actually changed, so this results in nginx spinning in the event loop till current time changes. While such timers are not expected to appear under normal conditions, as all such timers should be removed on previous event loop iterations, they still can appear due to bugs, zero timeouts set in the configuration (if this is not explicitly handled by the code), or due to external time changes on systems without clock_gettime(CLOCK_MONOTONIC). Fix is to call ngx_event_expire_timers() unconditionally. Calling it on each event loop iteration is not expected to be significant from performance point of view, especially compared to a syscall in ngx_process_events().
2021-03-30Merged with the default branch.Sergey Kandaurov1-3/+1
2021-03-10Merged with the default branch.Sergey Kandaurov1-1/+1
2021-03-05Events: fixed eventport handling in ngx_handle_read_event().Maxim Dounin1-1/+1
The "!rev->ready" test seems to be a typo, introduced in the original commit (719:f30b1a75fd3b). The ngx_handle_write_event() code properly tests for "rev->ready" instead. Due to this typo, read events might be unexpectedly removed during proxying after an event on the other part of the proxied connection. Catched by mail proxying tests.
2020-11-10QUIC: renamed c->qs to c->quic.Roman Arutyunyan1-3/+3
2020-07-21QUIC: added "quic" listen parameter.Roman Arutyunyan1-0/+10
The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there
2020-03-13HTTP/3.Roman Arutyunyan1-2/+34
2019-12-27SSL: reworked posted next events again.Maxim Dounin1-1/+1
Previous change 1ce3f01a4355 incorrectly introduced processing of the ngx_posted_next_events queue at the end of operation, effectively making posted next events a nop, since at the end of an event loop iteration the queue is always empty. Correct approach is to move events to the ngx_posted_events queue at an iteration start, as it was done previously. Further, in some cases the c->read event might be already in the ngx_posted_events queue, and calling ngx_post_event() with the ngx_posted_next_events queue won't do anything. To make sure the event will be correctly placed into the ngx_posted_next_events queue we now check if it is already posted.
2019-12-24SSL: reworked posted next events.Maxim Dounin1-2/+1
Introduced in 9d2ad2fb4423 available bytes handling in SSL relied on connection read handler being overwritten to set the ready flag and the amount of available bytes. This approach is, however, does not work properly when connection read handler is changed, for example, when switching to a next pipelined request, and can result in unexpected connection timeouts, see here: http://mailman.nginx.org/pipermail/nginx-devel/2019-December/012825.html Fix is to introduce ngx_event_process_posted_next() instead, which will set ready and available regardless of how event handler is set.
2019-10-17SSL: available bytes handling (ticket #1431).Maxim Dounin1-0/+7
Added code to track number of bytes available in the socket. This makes it possible to avoid looping for a long time while working with fast enough peer when data are added to the socket buffer faster than we are able to read and process data. When kernel does not provide number of bytes available, it is retrieved using ioctl(FIONREAD) as long as a buffer is filled by SSL_read(). It is assumed that number of bytes returned by SSL_read() is close to the number of bytes read from the socket, as we do not use SSL compression. But even if it is not true for some reason, this is not important, as we post an additional reading event anyway. Note that data can be buffered at SSL layer, and it is not possible to simply stop reading at some point and wait till the event will be reported by the kernel again. This can be only done when there are no data in SSL buffers, and there is no good way to find out if it's the case. Instead of trying to figure out if SSL buffers are empty, this patch introduces events posted for the next event loop iteration - such events will be processed only on the next event loop iteration, after going into the kernel and retrieving additional events. This seems to be simple and reliable approach.
2018-07-12Events: added configuration check on the number of connections.Maxim Dounin1-0/+15
There should be at least one worker connection for each listening socket, plus an additional connection for channel between worker and master, or starting worker processes will fail.
2018-07-12Events: moved sockets cloning to ngx_event_init_conf().Maxim Dounin1-0/+25
Previously, listenings sockets were not cloned if the worker_processes directive was specified after "listen ... reuseport". This also simplifies upcoming configuration check on the number of worker connections, as it needs to know the number of listening sockets before cloning.
2017-03-28Core: set nginx_shared_zone name via ngx_str_set().Ruslan Ermilov1-2/+1
2017-03-02Added missing static specifiers.Eran Kornblau1-15/+15
2016-07-15Events: support for EPOLLEXCLUSIVE.Valentin Bartenev1-3/+26
This flag appeared in Linux 4.5 and is useful for avoiding thundering herd problem. The current Linux kernel implementation walks the list of exclusive waiters, and queues an event to each epfd, until it finds the first waiter that has threads blocked on it via epoll_wait().
2016-07-15Events: the "accept_mutex" directive is turned off by default.Valentin Bartenev1-1/+1
Now it is believed that the accept mutex brings more harm than benefits. Especially in various benchmarks it often results in situation where only one worker grabs all connections.
2016-03-31Fixed logging.Sergey Kandaurov1-1/+1
2016-03-28Fixed --test-build-*.Ruslan Ermilov1-1/+1
Fixes various aspects of --test-build-devpoll, --test-build-eventport, and --test-build-epoll. In particular, if --test-build-devpoll was used on Linux, then "devpoll" event method would be preferred over "epoll". Also, wrong definitions of event macros were chosen.
2016-01-20Stream: UDP proxy.Roman Arutyunyan1-1/+3
2016-02-04Dynamic modules: changed ngx_modules to cycle->modules.Maxim Dounin1-21/+23
2016-02-04Dynamic modules: moved module-related stuff to separate files.Maxim Dounin1-8/+1
2015-10-20Win32: timer_resolution now ignored with select.Maxim Dounin1-0/+9
As setitimer() isn't available on Windows, time wasn't updated at all if timer_resolution was used with the select event method. Fix is to ignore timer_resolution in such cases.
2015-06-05Style.Maxim Dounin1-1/+2
2015-05-21Fixed reuseport with accept_mutex.Maxim Dounin1-1/+6
2015-05-20The "reuseport" option of the "listen" directive.Maxim Dounin1-0/+6
When configured, an individual listen socket on a given address is created for each worker process. This allows to reduce in-kernel lock contention on configurations with high accept rates, resulting in better performance. As of now it works on Linux and DragonFly BSD. Note that on Linux incoming connection requests are currently tied up to a specific listen socket, and if some sockets are closed, connection requests will be reset, see https://lwn.net/Articles/542629/. With nginx, this may happen if the number of worker processes is reduced. There is no such problem on DragonFly BSD. Based on previous work by Sepherosa Ziehau and Yingqi Lu.
2015-04-29Removed the deprecated "connections" directive.Ruslan Ermilov1-13/+0
2015-04-27Core: fixed nginx_shared_zone name.Maxim Dounin1-1/+1
2015-04-23Removed the obsolete rtsig module.Ruslan Ermilov1-54/+4
2015-04-22Removed the obsolete aio module.Ruslan Ermilov1-2/+2
2015-03-26Replaced the remaining NGX_OLD_THREADS check with NGX_WIN32.Ruslan Ermilov1-1/+3
2015-03-20Removed ngx_connection_t.lock.Ruslan Ermilov1-4/+0
2015-03-20Removed unix ngx_threaded and related ngx_process_changes.Ruslan Ermilov1-1/+1
2015-03-14Thread pools implementation.Valentin Bartenev1-1/+1
2015-03-04Renamed NGX_THREADS to NGX_OLD_THREADS because of deprecation.Ruslan Ermilov1-2/+2
It's mostly dead code and the original idea of worker threads has been rejected.
2014-09-01Events: processing of posted events changed from LIFO to FIFO.Valentin Bartenev1-9/+5
In theory, this can provide a bit better distribution of latencies. Also it simplifies the code, since ngx_queue_t is now used instead of custom implementation.
2014-09-01Events: removed broken thread support from posted events.Valentin Bartenev1-21/+1
It's mostly dead code. And the idea of thread support for this task has been deprecated.
2013-10-02Unused macro and variable removed.Sergey Kandaurov1-1/+0
The macro NGX_HTTP_DAV_COPY_BLOCK is not used since 8101d9101ed8 (0.8.9). The variable ngx_accept_mutex_lock_file was never used.
2013-05-31Win32: accept_mutex now always disabled (ticket #362).Maxim Dounin1-0/+11
Use of accept mutex on win32 may result in a deadlock if there are multiple worker_processes configured and the mutex is grabbed by a process which can't accept connections.
2013-03-15Status: introduced the "ngx_stat_waiting" counter.Valentin Bartenev1-1/+5
And corresponding variable $connections_waiting was added. Previously, waiting connections were counted as the difference between active connections and the sum of reading and writing connections. That made it impossible to count more than one request in one connection as reading or writing (as is the case for SPDY). Also, we no longer count connections in handshake state as waiting.