summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_router.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-09-29Fixing request buffer memory leakage in router.Max Romanov1-0/+3
The issue was introduced in changeset 1d84b9e4b459. The request buffer was transferred via the shared application queue, but the buffer position and the 'sent' flag were not updated after the buffer had been sent.
2020-08-28Router: fixed "pass" to upstreams.hongzhidao1-0/+4
Messed up return values in nxt_upstream_find() caused error in applying any configuration with a valid "pass" value in router configuration pointing to upstream. That wasn't the case in "listeners" objects, where the return value wasn't checked. Also, it caused segfault in cases where the "pass" option was configured with variables and resulting value was pointing to a non-existent upstream. Added missing return checks as well to catch possible memory allocation errors. The bug was introduced in d32bc428f46b. This closes #472 issue on GitHub.
2020-09-15Python: changed request headers format in router protocol.Max Romanov1-1/+1
The coming ASGI support requires raw HTTP headers format. Headers grouping and upcase code were moved to WSGI module.
2020-08-21Configuration: removed "reschedule_timeout" option.Valentin Bartenev1-11/+0
It's not used since cbcd76704c90. This option is a leftover from previous IPC between router and applications processes. It was never documented, though. Thanks to 洪志道 (Hong Zhi Dao).
2020-08-13Fixing router assertion in result of application prefork error.Max Romanov1-0/+8
Buffer for application prefork request allocated from temp conf mem_pool. If error response from main process received before buffer completion handler, temp conf mem_pool destroyed and router may crash in completion handler. Assertion "src/nxt_buf.c:208 assertion failed: data == b->parent" triggered when NXT_DEBUG_ALLOC enabled in configure. This patch disables completion handler and memory allocated for buffer released with memory pool.
2020-08-13Basic variables support.Valentin Bartenev1-44/+139
2020-08-12Responding with error in case of first process start failure.Max Romanov1-18/+124
After shared application port introducing, request queue in router was removed and requests may stuck forever waiting for another process start.
2020-08-11Style fixes for 2 file descriptors transfer over port.Max Romanov1-16/+16
Two consecutive fd and fd2 fields replaced with array.
2020-08-11Introducing application and port shared memory queues.Max Romanov1-22/+179
The goal is to minimize the number of syscalls needed to deliver a message.
2020-08-11Made router port message handlers into static functions.Max Romanov1-4/+13
Mostly harmless.
2020-08-11Adding debug messages to catch process management issues.Max Romanov1-2/+36
2020-08-11Introducing the shared application port.Max Romanov1-1042/+462
This is the port shared between all application processes which use it to pass requests for processing. Using it significantly simplifies the request processing code in the router. The drawback is 2 more file descriptors per each configured application and more complex libunit message wait/read code.
2020-08-11Changing router to application shared memory exchange protocol.Max Romanov1-3/+66
The application process needs to request the shared memory segment from the router instead of the latter pushing the segment before sending a request to the application. This is required to simplify the communication between the router and the application and to prepare the router for using the application shared port and then the queue.
2020-08-11Changing router to application port exchange protocol.Max Romanov1-17/+83
The application process needs to request the port from the router instead of the latter pushing the port before sending a request to the application. This is required to simplify the communication between the router and the application and to prepare the router to use the application shared port and then the queue.
2020-08-09Fixing leaked configuration objects.Max Romanov1-4/+30
If there are no listen sockets, the router configuration usage counter remains 0 and never decreases. The only moment to release a configuration is right after a configuration update.
2020-08-09Fixing connection remote sockaddr leakage.Max Romanov1-2/+4
Earlier patch 1bf971f83571 fixes connection leakage. But connection free requires separate remote sockaddr release.
2020-08-07Fixing listen event connection leakage.Max Romanov1-0/+4
A connection object is allocated in advance for each listen event object to be used for the established connection. This connection needs to be freed when the listen event is destroyed.
2020-07-25Using plain shared memory for configuration pass.Max Romanov1-14/+35
There is no restrictions on configration size and using segmented shared memory only doubles memory usage because to parse configration on router side, it needs to be 'plain' e. g. located in single continous memory buffer.
2020-07-23Fixing request_app_link reference counting.Max Romanov1-4/+2
Racing conditions reproduced periodically on test_python_process_switch.
2020-07-06Destroying temporary router configuration.Igor Sysoev1-28/+40
The lifespan of a listening socket is longer than both router configuration's and temporary router configuration's lifespan, so the sockets should be stored in persistent queues. Safety is ensured by the fact that the router processes only one new configuration at any time.
2020-03-09Refactor of process management.Tiago Natel de Moura1-9/+35
The process abstraction has changed to: setup(task, process) start(task, process_data) prefork(task, process, mp) The prefork() occurs in the main process right before fork. The file src/nxt_main_process.c is completely free of process specific logic. The creation of a process now supports a PROCESS_CREATED state. The The setup() function of each process can set its state to either created or ready. If created, a MSG_PROCESS_CREATED is sent to main process, where external setup can be done (required for rootfs under container). The core processes (discovery, controller and router) doesn't need external setup, then they all proceeds to their start() function straight away. In the case of applications, the load of the module happens at the process setup() time and The module's init() function has changed to be the start() of the process. The module API has changed to: setup(task, process, conf) start(task, data) As a direct benefit of the PROCESS_CREATED message, the clone(2) of processes using pid namespaces now doesn't need to create a pipe to make the child block until parent setup uid/gid mappings nor it needs to receive the child pid.
2020-05-28Added NULL check for engine->port.Max Romanov1-2/+4
This is required to handle REMOVE_PID messages if router engine initialization is incomplete.
2020-05-15Router: removed two unused assignments.Valentin Bartenev1-2/+2
This should resolve some static analyzers warnings.
2020-05-14PHP: implemented "targets" option.Valentin Bartenev1-10/+54
This allows to specify multiple subsequent targets inside PHP applications. For example: { "listeners": { "*:80": { "pass": "routes" } }, "routes": [ { "match": { "uri": "/info" }, "action": { "pass": "applications/my_app/phpinfo" } }, { "match": { "uri": "/hello" }, "action": { "pass": "applications/my_app/hello" } }, { "action": { "pass": "applications/my_app/rest" } } ], "applications": { "my_app": { "type": "php", "targets": { "phpinfo": { "script": "phpinfo.php", "root": "/www/data/admin", }, "hello": { "script": "hello.php", "root": "/www/data/test", }, "rest": { "root": "/www/data/example.com", "index": "index.php" }, } } } }
2020-05-14Configuration: URI encoding in the "pass" option.Valentin Bartenev1-2/+5
This is useful to escape "/" in path fragments. For example, in order to reference the application named "foo/bar": { "pass": "applications/foo%2Fbar" }
2020-04-16Using malloc/free for the http fields hash.Max Romanov1-1/+1
This is required due to lack of a graceful shutdown: there is a small gap between the runtime's memory pool release and router process's exit. Thus, a worker thread may start processing a request between these two operations, which may result in an http fields hash access and subsequent crash. To simplify issue reproduction, it makes sense to add a 2 sec sleep before exit() in nxt_runtime_exit().
2020-04-10Resolving a racing condition while adding ports on the app's side.Max Romanov1-3/+3
An earlier attempt (ad6265786871) to resolve this condition on the router's side added a new issue: the app could get a request before acquiring a port.
2020-04-06Fixing 'find & add' racing condition in connected ports hash.Max Romanov1-14/+18
Missing error log messages added.
2020-03-17Fixing body fd access racing condition.Max Romanov1-16/+31
To avoid closing the body fd prematurely, the fd value is moved from the request struct to the app link. The body fd should not be closed immediately after the request is sent to the application due to possible request rescheduling.
2020-03-12Using disk file to store large request body.Max Romanov1-3/+34
This closes #386 on GitHub.
2020-03-12Moving request memory pool retain call after RPC data allocation.Max Romanov1-0/+15
If the call is done only after a successful RPC data allocation, its corresponding release call is not missed, which avoids a potential leak.
2020-03-06Round robin upstream added.Igor Sysoev1-0/+11
2020-03-04Refactored nxt_http_action.Igor Sysoev1-3/+5
2020-03-03Fixing request_app_link reference counting for delayed requests.Max Romanov1-9/+36
Router built with debug may stop with assertion during stalled requests re-schedule. This was caused by missing reference counting increment before nxt_router_port_select() call.
2020-02-03Fixed req_app_link reference counting on cancellation.Max Romanov1-16/+7
Re-scheduled req_app_link structures should have use_count exactly equal to the number of references from the application and port list. However, there's one extra usage decrement that occurs after the req_app_link is created because the use_count is initialised as 1. This patch removes all excess instances of the usage decrement that caused preliminary req_app_link release and router process crash. To reproduce the issue need to cause request rescheduling between 2 app processes. This issue was introduced in 61e9f23a566d.
2019-12-24Introducing port messages to notify about out of shared memory.Max Romanov1-0/+56
- OOSM (out of shared memory). Sent by application process to router when application reaches the limit of allocated shared memory and needs more. - SHM_ACK. Sent by router to application when the application's shared memory is released and the OOSM flag is enabled for the segment. This implements blocking mode (the library waits for SHM_ACK in case of out of shared memory condition and retries allocating the required memory amount) and non-blocking mode (the library notifies the application that it's out of shared memory and returns control to the application module that sets up the output queue and puts SHM_ACK in the main message loop).
2019-11-26Refactoring reference counting of req_app_link.Max Romanov1-34/+48
The reason for the change is that the req_app_link reference count was incorrect if the application crashed at start; in this case, the nxt_request_app_link_update_peer() function was never called. This closes #332 issue on GitHub.
2019-11-14Initial proxy support.Igor Sysoev1-1/+8
2019-11-14Introduced chained buffer completion handlers.Igor Sysoev1-2/+7
2019-11-14Replacing pass with action.Igor Sysoev1-7/+7
2019-10-10Style fixes.Igor Sysoev1-1/+2
2019-09-19Basic support for serving static files.Valentin Bartenev1-1/+92
2019-08-30Fixed WebSocket implementation that was broken on some systems.Max Romanov1-1/+1
The "nxt_http_websocket" request state, defined in "nxt_http_websocket.c", is used in "nxt_router.c" and must be linked with external symbol declared in "nxt_router.c". Due to the missing "extern" keyword, building Unit with some linkers (notably gold and LLD) caused WebSocket connections to get stuck or even crash the router process.
2019-08-26Adding body handler to nxt_http_request_header_send().Igor Sysoev1-6/+1
2019-08-20Introducing websocket support in router and libunit.Max Romanov1-71/+110
2019-08-16Changing the sequence of body send execution.Max Romanov1-2/+6
Request state ready_handler required for further websocket events processing. It is not required for regular response transferring.
2019-08-16Improving response header fields processing.Max Romanov1-8/+18
Fields are filtered one by one before being added to fields list. This avoids adding and then skipping connection-specific fields.
2019-08-14Renaming supplemental request structures in router.Max Romanov1-347/+418
- nxt_req_app_link_t -> nxt_request_app_link_t - nxt_req_conn_link_t -> nxt_request_rpc_data_t Corresponding abbreviated field names also changed: - ra -> req_app_link - rc -> req_rpc_data
2019-08-06Router: allowed empty configurations.Valentin Bartenev1-191/+189
Now it's possible to delete "listeners" and "applications" objects. This closes #187 issue on GitHub.
2019-08-06Refactored HTTP protocol callback table.Igor Sysoev1-1/+1