Commit Graph

79 Commits

Author SHA1 Message Date
Zhidao HONG
5fa5b1464f Configuration: automatic migration to the new "share" behavior. 2021-10-09 10:44:31 +08:00
Max Romanov
fa9fb29be2 Application restart introduced.
When processing a restart request, the router sends a QUIT message to all
existing processes of the application.  Then, a new shared application port is
created to ensure that new requests won't be handled by the old processes of
the application.
2021-07-29 19:50:39 +03:00
Max Romanov
8c88537e6e Using shared memory to pass configuration to main process.
This patch is required to remove fragmented messages functionality.
2021-02-03 23:23:06 +03:00
Max Romanov
f147943f63 Style fixes for 2 file descriptors transfer over port.
Two consecutive fd and fd2 fields replaced with array.
2020-08-11 21:48:27 +03:00
Max Romanov
c617480eef Using plain shared memory for configuration pass.
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-25 11:06:32 +03:00
Tiago Natel de Moura
e9e5ddd5a5 Refactor of process management.
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-03-09 16:28:25 +00:00
Max Romanov
3ec72362b9 Waiting for router instead of reporting to user on config update. 2020-05-12 16:25:24 +03:00
Max Romanov
50f9816daa Blocking config change when applying the initial router config. 2020-05-12 16:25:16 +03:00
Max Romanov
6bda9b5eeb Using malloc/free for the http fields hash.
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-16 17:09:23 +03:00
Valentin Bartenev
c7f5c1c664 Controller: improved handling of unix domain control socket.
One of the ways to detect Unit's startup and subsequent readiness to accept
commands relies on waiting for the control socket file to be created.
Earlier, it was unreliable due to a race condition between the client's
connect() and the daemon's listen() calls after the socket's bind() call.

Now, unix domain listening sockets are created with a nxt_listen_socket_create()
call as follows:

   s = socket();
   unlink("path/to/socket.tmp")
   bind(s, "path/to/socket.tmp");
   listen(s);
   rename("path/to/socket.tmp", "path/to/socket");

This eliminates a time-lapse when the socket file is already created but nobody
is listening on it yet, which therefore prevents the condition described above.

Also, it allows reliably detecting whether the socket is being used or simply
wasn't cleaned after the daemon stopped abruptly.  A successful connection to
the socket file means the daemon has been started; otherwise, the file can be
overwritten.
2020-04-08 15:15:24 +03:00
Valentin Bartenev
555d595f38 Removed unused code related to testing of address binding. 2020-04-08 15:15:24 +03:00
Valentin Bartenev
27c1e26856 Controller: eliminated extra control socket's sockaddr copying. 2020-04-08 15:15:24 +03:00
Valentin Bartenev
d198a105eb Configuration: removing UTF-8 BOM from the input JSON.
Some editors can add it to JSON files.
2020-02-20 17:58:24 +03:00
Valentin Bartenev
64be8717bd Configuration: added ability to access object members with slashes.
Now URI encoding can be used to escape "/" in the request path:

  GET /config/listeners/unix:%2Fpath%2Fto%2Fsocket/
2019-09-16 20:17:42 +03:00
Valentin Bartenev
6a6bc63c48 Configuration: support for POST operations on arrays.
It allows to add an array element without specifying the index.
2019-04-24 20:31:00 +03:00
Max Romanov
1b7514dca3 Destroying pool in case of error.
This closes #233 issue on GitHub.
Thanks to 洪志道 (Hong Zhi Dao).
2019-03-22 15:32:40 +03:00
Max Romanov
9f29ac9f3e Preserving inherited engine memory pool in controller process.
The pool is inherited from master process since changeset 854a1a440616.
2018-09-20 15:50:48 +03:00
Valentin Bartenev
8d844bc2aa Controller: certificates storage interface. 2018-09-20 15:27:08 +03:00
Valentin Bartenev
145d895430 Controller: fixed handling of zero Content-Length. 2018-07-02 16:36:59 +03:00
Valentin Bartenev
1a52d876f7 Introduced nxt_length() macro. 2018-06-25 16:51:47 +03:00
Valentin Bartenev
3e8dbfe5ff Added SERVER_SOFTWARE request meta-variable. 2018-05-21 16:14:24 +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
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
c610b35649 Controller: added "/config" prefix for the configuration object. 2018-04-11 18:23:58 +03:00
Valentin Bartenev
96927e7d0c Controller: fixed a memory leak when PUT operation failed.
Thanks to 洪志道 (Hong Zhi Dao).
2018-04-08 14:08:06 +03:00
Valentin Bartenev
bebc5845f8 Capitalization in the "Server" field. 2018-03-13 20:32:47 +03:00
Valentin Bartenev
912a49c609 Reduced number of critical log levels. 2018-03-05 17:32:50 +03:00
Valentin Bartenev
8830d73261 HTTP parser: reworked header fields handling. 2017-12-25 17:04:22 +03:00
Igor Sysoev
80e8ce8322 A number of engine connections is decreased on connection close. 2017-11-27 17:52:28 +03:00
Max Romanov
51396fea83 Checking the result of shared memory buffer allocation.
This closes #57 issue on GitHub.
2017-10-25 15:09:07 +03:00
Igor Sysoev
67c066b026 Router: fixed segfault after configuration change. 2017-10-18 18:05:47 +03:00
Valentin Bartenev
1c6d4d8cff Basic validation errors. 2017-10-10 19:46:58 +03:00
Max Romanov
85e485776b Using port 'post' facility to proxy remove pid message to workers.
Remove pid proxying to worker engines implementation was originally
overcomplicated.  Memory pool and 2 engine posts (there and back again) are
optimized out and replaced with band new nxt_port_post() call.
2017-10-04 15:01:15 +03:00
Max Romanov
414d508e04 Using engine memiory pool for port write allocations.
To allow use port from different threads, the first step is to avoid using
port's memory pool for temporary allocations required to send data through
the port.  Including but not limited by:
  - buffers for data;
  - send message structures;
  - new mmap fd notifications;

It is still safe to use port memory pool for incoming buffers allocations
because recieve operation bound to single thread.
2017-10-04 14:58:13 +03:00
Igor Sysoev
bfa808d689 Event engine memory cache for nxt_sockaddr_t.
Introducing event engine memory cache and using the cache for
nxt_sockaddr_t structures.
2017-09-27 19:22:59 +03:00
Max Romanov
838d9946ac Introducing named port message handlers to avoid misprints. 2017-09-15 20:30:34 +03:00
Valentin Bartenev
90ae152ce0 Fixed port handlers arrays. 2017-09-15 14:38:22 +03:00
Valentin Bartenev
4953e5b5cb Configuration persistence.
Now configuration survives server reloads.
2017-09-10 06:22:15 +03:00
Igor Sysoev
4d5e39e8c1 Fixed textual socket name lengths and Unix domain sockaddr length. 2017-09-14 18:16:22 +03:00
Igor Sysoev
f0e9e3ace9 nginext has been renamed to unit. 2017-08-31 00:42:16 +03:00
Valentin Bartenev
55fe80600c Controller: resending configuration to router after its restart.
Now router crash can be survived with less damage.
2017-08-30 03:10:13 +03:00
Valentin Bartenev
f528cb393a Controller: waiting for router before start to accept connections.
Previously, reconfiguration might fail right after the daemon start
if the router process wasn't ready yet.
2017-08-30 03:10:13 +03:00
Valentin Bartenev
e21dbf89e6 Controller: correct handling of missing router port.
There's no router port if the router process is just crashed
or hasn't started yet.
2017-08-30 03:09:06 +03:00
Igor Sysoev
9d487df10d The master process has been renamed to the main process. 2017-08-29 02:59:35 +03:00
Valentin Bartenev
1a5ec7fd08 Improved reconfiguration requests serialization.
Previously, only applying of updated configuration was serialized,
while the changes themselves could be done in parallel on the same
configuration.  That resulted in inconsistent behaviour.
2017-08-28 10:20:40 +03:00
Igor Sysoev
0d65c896cf Added configure and command line option --control. 2017-08-26 13:37:44 +03:00
Valentin Bartenev
e2653f7ba5 Fixed building by GCC after 7d1017bd0f6c. 2017-08-13 15:58:44 +03:00
Valentin Bartenev
80deee3903 Controller: more HTTP headers and detailed JSON parsing errors. 2017-08-11 19:54:40 +03:00
Valentin Bartenev
617da0d023 Fixed building without debug after c1ae75b4e17c and 6281674ecf4f. 2017-08-04 18:00:40 +03:00
Max Romanov
bcf99f87e2 Using port rpc in controller->router configuration update. 2017-08-02 13:20:57 +03:00