Commit Graph

174 Commits

Author SHA1 Message Date
Igor Sysoev
7935ea4543 Round robin upstream added. 2020-03-06 18:28:54 +03:00
Igor Sysoev
643d4383fa Refactored nxt_http_action. 2020-03-04 14:03:32 +03:00
Max Romanov
9e295fa314 Fixing request_app_link reference counting for delayed requests.
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-03-03 18:28:26 +03:00
Max Romanov
7ea9ebc55a Fixed req_app_link reference counting on cancellation.
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.
2020-02-03 11:20:59 +03:00
Max Romanov
df7caf4650 Introducing port messages to notify about out of shared memory.
- 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-12-24 18:04:13 +03:00
Max Romanov
4eecf1cb6a Refactoring reference counting of req_app_link.
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-26 17:14:53 +03:00
Igor Sysoev
ddde9c23cf Initial proxy support. 2019-11-14 16:39:54 +03:00
Igor Sysoev
57e326b411 Introduced chained buffer completion handlers. 2019-11-14 16:39:48 +03:00
Igor Sysoev
14e56fe8c8 Replacing pass with action. 2019-11-14 16:39:48 +03:00
Igor Sysoev
09e7357b08 Style fixes. 2019-10-10 19:42:41 +03:00
Valentin Bartenev
08a8d1510d Basic support for serving static files. 2019-09-19 02:47:09 +03:00
Max Romanov
7053a35a60 Fixed WebSocket implementation that was broken on some systems.
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-30 00:07:54 +03:00
Igor Sysoev
e2abfaf381 Adding body handler to nxt_http_request_header_send(). 2019-08-26 18:29:00 +03:00
Max Romanov
e501c74ddc Introducing websocket support in router and libunit. 2019-08-20 16:31:53 +03:00
Max Romanov
686f5b1436 Changing the sequence of body send execution.
Request state ready_handler required for further websocket events processing.
It is not required for regular response transferring.
2019-08-16 14:55:18 +03:00
Max Romanov
29911538ea Improving response header fields processing.
Fields are filtered one by one before being added to fields list.
This avoids adding and then skipping connection-specific fields.
2019-08-16 00:56:38 +03:00
Max Romanov
1b095ff417 Renaming supplemental request structures in router.
- 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-14 23:59:46 +03:00
Valentin Bartenev
274260bd28 Router: allowed empty configurations.
Now it's possible to delete "listeners" and "applications" objects.

This closes #187 issue on GitHub.
2019-08-06 17:13:13 +03:00
Igor Sysoev
17bb22a4e4 Refactored HTTP protocol callback table. 2019-08-06 15:29:39 +03:00
Max Romanov
ce17fef73d Fixed application crash handling in router.
Before this fix, request in router may hang until timeout expired if
application crashed during request processing.
2019-06-28 12:19:54 +03:00
Max Romanov
452ce0789e Adjusting request schema value according to connection tls state.
This closes #223 issue on GitHub.
2019-03-21 13:55:57 +03:00
Max Romanov
39e147a858 Removing unused local variable. 2019-03-18 19:55:39 +03:00
Alexander Borisov
dccb4cf354 Removed unnecessary abstraction layer. 2019-03-06 15:26:45 +03:00
Max Romanov
5bfdebb9e4 Introducing Java Servlet Container beta. 2019-02-28 18:02:42 +03:00
Max Romanov
b92dc6036c Removing app data debug message.
This message produces too many noise in log and complicates analysis.
2019-02-28 14:37:39 +03:00
Valentin Bartenev
e929d08201 Fixed processing of SERVER_NAME after 77aad2c142a0.
Previously, the nxt_router_prepare_msg() function expected server host among
other headers unmodified.  It's not true anymore since normalization of the
Host header has been introduced in 77aad2c142a0.

The nxt_unit_split_host() function was removed.  It didn't work correctly with
IPv6 literals.  Anyway, after 77aad2c142a0 the port splitting is done in router
while Host header processing.
2019-02-27 17:25:07 +03:00
Igor Sysoev
d4ccaae900 Initial routing implementation. 2019-02-27 16:41:11 +03:00
Valentin Bartenev
d8c0a0dbe2 Disabled useless code in nxt_router_listen_socket_error().
It doesn't do anything useful, among creating a JSON message and logging it
to debug log.  Besides that it causes segmentation fault if the RPC handler
is triggered with an empty buffer due to exiting of the main process.
2019-02-25 15:10:44 +03:00
Igor Sysoev
c96b2baca5 TLS certificates should be freed per listener.
This fixes memory leak if configuration uses more than one TLS cerificate.
2019-02-22 17:32:38 +03:00
Igor Sysoev
bb11e9036f Fixed memory leak on response body sending failure. 2019-02-18 17:28:55 +03:00
Valentin Bartenev
da0ef366dc Handling of timers with bias.
Timers that don't require maximum precision (most of them, actually) can be
triggered earlier or later within the bias interval.

To reduce wakeups by timers, the expire function now triggers not only all
timers that fall within the elapsed time, but also those whose bias falls
within this interval.
2018-10-22 16:04:16 +03:00
Valentin Bartenev
029c1a9f50 Renamed "go" application type to "external".
There's nothing specific to Go language.  This type of application object can
be used to run any external application that utilizes libunit API.
2018-10-09 17:53:31 +03:00
Max Romanov
9fe6e75d35 Preventing port from release in asynchronous operations.
Router reconfiguration may lead to starting new application processes, opening
listen ports etc.  These actions are asynchronous and require message
exchange with master process.  Router stores reference for controller
(response) port in structure associated with reconfiguration process (tmcf).
The port used to provide reconfiguration response (either success or failed)
to controller.

This commit increases response port use counter to make sure port structure
not freed while router waits for result of asynchronous operations.
2018-09-20 16:16:32 +03:00
Valentin Bartenev
8d844bc2aa Controller: certificates storage interface. 2018-09-20 15:27:08 +03:00
Igor Sysoev
96cd68b340 Added SSL/TLS support on connection level. 2018-09-20 15:05:37 +03:00
Max Romanov
e964e982fd Initializing application structure with 0 to avoid crash.
Attribute 'application' is optional in listener object.  This commit adds
missing code to reset 'lscf' to avoid garbage and crash when the attribute
is absent.
2018-09-19 19:24:56 +03:00
Max Romanov
86740ab34b Introducing app joint to accurate app release.
For accurate app descriptor release, it is required to count the number of
use counts.  Use count increased when:
- app linked to configuration app queue;
- socket conf stores pointer to app;
- request for start app process posted to router service thread;

Application port has pointer to app, but it does not increase use count
to avoid use count loop.

Timer needs a pointer to nxt_timer_t which is stored in engine timers tree.
nxt_timer_t now resides in nxt_app_joint_t and does not lock the application.

Start process port RPC handlers is also linked to nxt_app_joint_t.

App joint (nxt_app_joint_t) is a 'weak pointer':
- single threaded;
- use countable;
- store pointer to nxt_app_t (which can be NULL);

nxt_app_t has pointer to nxt_app_joint_t and update its pointer to app.
2018-08-10 19:27:13 +03:00
Max Romanov
1bb22d1e92 Unit application library.
Library now used in all language modules.
Old 'nxt_app_*' code removed.

See src/test/nxt_unit_app_test.c for usage sample.
2018-08-06 17:27:33 +03:00
Valentin Bartenev
1abdcfb2d8 Controller: added "settings" configuration object.
It has the following structure and default values:

  {
      "http": {
          "header_read_timeout": 30,
          "body_read_timeout": 30,
          "send_timeout": 30,
          "idle_timeout": 180,
          "max_body_size": 8388608
      }
  }
2018-07-09 20:34:51 +03:00
Valentin Bartenev
5a05f569b7 Router: increased HTTP connection related limits. 2018-07-09 20:34:51 +03:00
Valentin Bartenev
7e3de003c7 PHP: fixed request body processing.
The implementation of module was based on the assumption that PHP reads request
body and headers in the particular order.  For the POST request the body goes
before headers and vice versa for all other requests.

But as it appeared later, this order is unspecified and depends on many factors,
including the particular code of PHP application.  Among other factors those
can affect ordering:

 - presence of "Content-Type" header;
 - "variables_order" php.ini setting;
 - "enable_post_data_reading" php.ini setting;
 - reading php://input by application;

and this list can be incomplete.

As a temporary workaround, request body now is always put before headers and it
is gracefully skipped whenever PHP wants to get headers.

This closes #144 issue on GitHub.
2018-07-05 16:43:45 +03:00
Valentin Bartenev
1a52d876f7 Introduced nxt_length() macro. 2018-06-25 16:51:47 +03:00
Igor Sysoev
ff6ca2a82c Fixed keep-alive hanging after reconfiguration. 2018-05-30 18:46:05 +03:00
Max Romanov
07204789bc Eliminating possible NULL pointer dereference.
Found by Coverity (CID 276138).
2018-04-27 20:32:50 +03:00
Max Romanov
179819dbee Controller waits READY message from router.
This required to avoid racing condition when controller receive router
port before router receives controller port.
2018-04-26 16:44:20 +03:00
Valentin Bartenev
a20830ff55 Router: fixed race condition while access log reopening.
In order to reopen access log, the router process creates a memory pool
and allocates a buffer to send RPC message for the main process.

Previously, the memory pool was destroyed when RPC response handler was
called.  It appeared, that the buffer completion handler could be not
triggered by that time and still remained in a queue.

Now the memory pool is destroyed only after both events are happen.
2018-04-19 19:48:58 +03:00
Valentin Bartenev
54ccb32333 Added missing cleanup when nxt_port_socket_write() failed. 2018-04-18 17:28:04 +03:00
Valentin Bartenev
ab4f867996 Added missing checks if nxt_port_rpc_register_handler() failed.
This closes #97 issue on GitHub.
Thanks to 洪志道 (Hong Zhi Dao).
2018-04-17 21:13:43 +03:00
Valentin Bartenev
da61cfd98b Access log reopening. 2018-04-11 18:23:58 +03:00
Valentin Bartenev
204c394721 Initial access log support. 2018-04-11 18:23:33 +03:00