Commit Graph

1203 Commits

Author SHA1 Message Date
Alejandro Colomar
bce0f432c4 Removed special cases for non-NXT_CONF_VALUE_ARRAY.
The previous commit added more generic APIs for handling
NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together.
Modify calling code to remove special cases for arrays and
non-arrays, taking special care that the path for non arrays is
logically equivalent to the previous special cased code.
Use the now-generic array code only.
2022-04-26 12:38:48 +02:00
Alejandro Colomar
e525605d05 Added new array APIs that also work with non-arrays.
Similar to how C pointers to variables can always be considered as
pointers to the first element of an array of size 1 (see the
following code for an example of how they are equivalent),
treating non-NXT_CONF_VALUE_ARRAY as if they were
NXT_CONF_VALUE_ARRAYs of size 1 allows for simpler and more
generic code.

	void foo(ptrdiff_t sz, int arr[sz])
	{
		for (ptrdiff_t i = 0; i < sz; i++)
			arr[i] = 0;
	}

	void bar(void)
	{
		int  x;
		int  y[1];

		foo(1, &x);
		foo(1, y);
	}

nxt_conf_array_elements_count_or_1():
	Similar to nxt_conf_array_elements_count().
	Return a size of 1 when input is non-array, instead of
	causing undefined behavior.  That value (1) makes sense
	because it will be used as the limiter of a loop that
	loops over the array and calls
	nxt_conf_get_array_element_or_itself(), which will return
	a correct element for such loops.

nxt_conf_get_array_element_or_itself():
	Similar to nxt_conf_get_array_element().
	Return the input pointer unmodified (i.e., a pointer to
	the unique element of a hypothetical array), instead of
	returning NULL, which wasn't very useful.

nxt_conf_array_qsort():
	Since it's a no-op for non-arrays, this API can be reused.
2022-04-26 12:38:48 +02:00
Alejandro Colomar
940d695f82 Added 'const' for read-only function parameter.
That parameter is not being modified in the function.  Make it
'const' to allow passing 'static const' variables.
2022-04-26 12:38:48 +02:00
Zhidao HONG
aeed86c682 Workaround for the warning in nxt_realloc() on GCC 12.
This closes #639 issue on Github.
2022-02-22 19:18:18 +08:00
Zhidao HONG
4fcfb9d5fb Certificates: fixed crash when reallocating chain. 2022-02-14 20:14:03 +08:00
Max Romanov
bf6282b16c Python: fixing debug message field type.
Introduced in the 78864c9d5ba8 commit.

Sorry about that.
2022-02-09 10:37:51 +03:00
Max Romanov
2b5941df74 Python: fixing incorrect function object dereference.
The __call__ method can be native and not be a PyFunction type.  A type check
is thus required before accessing op_code and other fields.

Reproduced on Ubuntu 21.04, Python 3.9.4 and Falcon framework: here, the
App.__call__ method is compiled with Cython, so accessing op_code->co_flags is
invalid; accidentally, the COROUTINE bit is set which forces the Python module
into the ASGI mode.

The workaround is explicit protocol specification.

Note: it is impossible to specify the legacy mode for ASGI.
2022-02-08 12:04:41 +03:00
Max Romanov
818a78d82c Java: fixing multiple SCI initializations.
- Ignoring Tomcat WebSocket container initialization.
- Renaming application class loader to UnitClassLoader to avoid
development environment enablement in Spring Boot.

This closes #609 issue on GitHub.
2021-12-27 16:37:36 +03:00
Max Romanov
f845283820 Perl: creating input and error streams if closed.
Application handler can do anything with a stream object (including close it).
Once the stream is closed, Unit creates a new stream.

This closes #616 issue on GitHub.
2021-12-27 16:37:35 +03:00
Zhidao HONG
a6a884ebdb Fixed debug message broken in 45b25ffb2e8c. 2021-12-03 12:08:54 +08:00
Max Romanov
64db3ef1bb Fixing prototype process crash.
A prototype stores linked application processes structures.  When an
application process terminates, it's removed from the list.  To avoid double
removal, the pointer to the next element should be set to NULL.

The issue was introduced in c8790d2a89bb.
2021-12-01 18:05:50 +03:00
Max Romanov
8fb9f7f049 Fixing uninitialized structure field.
Port's "data" field may be used by application and thus need to be set to NULL.
The issue was introduced in the f8a0992944df commit.

Found by Coverity (CID 374352).
2021-12-01 18:05:16 +03:00
Valentin Bartenev
8c9228d19f Logging of the daemon version on startup. 2021-12-01 17:09:02 +03:00
Valentin Bartenev
f8237911d7 PHP: fixed crash when calling module functions in OPcache preload.
In PHP, custom fastcgi_finish_request() and overloaded chdir() functions can be
invoked by an OPcache preloading script (it runs when php_module_startup() is
called in the app process setup handler).  In this case, there was no runtime
context set so trying to access it caused a segmentation fault.

This closes #602 issue on GitHub.
2021-11-25 19:58:54 +03:00
Max Romanov
0af5f6ddb4 Fixing access_log structure reference counting.
The reference to the access_log structure is stored in the current
nxt_router_conf_t and the global nxt_router_t.  When the reference is copied,
the reference counter should be adjusted accordingly.

This closes #593 issue on GitHub.
2021-11-25 16:58:43 +03:00
Max Romanov
2bc9599057 Fixing zombie process appearance and hang up on shutdown.
After the c8790d2a89bb commit, the SIGCHLD handler may return before processing
all awaiting PIDs.  To avoid zombie processes and ensure successful main
process termination, waitpid() must be called until an error is returned.

This closes #600 issue on GitHub.
2021-11-24 13:11:50 +03:00
Max Romanov
9e2e69dd58 Fixing alerts on router restart.
Splitting the process type connectivity matrix to 'keep ports' and 'send
ports'; the 'keep ports' matrix is used to clean up unnecessary ports after
forking a new process, and the 'send ports' matrix determines which process
types expect to get created process ports.

Unfortunately, the original single connectivity matrix no longer works because
of an application stop delay caused by prototypes.  Existing applications
should not get the new router port at the moment.
2021-11-24 13:11:48 +03:00
Max Romanov
2c636a03f3 Sending shared port to application prototype.
Application process started with shared port (and queue) already configured.
But still waits for PORT_ACK message from router to start request processing
(so-called "ready state").

Waiting for router confirmation is necessary.  Otherwise, the application may
produce response and send it to router before the router have the information
about the application process.  This is a subject of further optimizations.
2021-11-24 13:11:47 +03:00
Valentin Bartenev
ef1ebf96f3 Fixed possible access to an uninitialized field.
The "recv_msg.incoming_buf" is checked after jumping to the "done" label
if nxt_socket_msg_oob_get_fds() returns an error.

Also moved initialization of "port_msg" near to its first usage.

Found by Coverity (CID 373899).
2021-11-23 15:36:24 +03:00
Valentin Bartenev
aed1c55a06 Removed the execute permission bit from "nxt_h1proto.c".
It was accidentally added in 4645a43bc248.
2021-11-11 18:54:10 +03:00
Tiago Natel de Moura
e207415a78 Introducing application prototype processes. 2021-11-09 15:48:44 +03:00
Tiago Natel de Moura
1de660b6df Changed nxt_process_* for reuse.
This enables the reuse of process creation functions.
2021-11-09 15:48:44 +03:00
Tiago Natel de Moura
ff6a7053f5 Introduced SCM_CREDENTIALS / SCM_CREDS in the socket control msgs. 2021-11-09 15:48:44 +03:00
Zhidao HONG
aee908bcbd Router: matching query string support.
The "query" option matches decoded arguments, including plus ('+') to
space (' ').  Like "uri", it can be a string or an array of strings.
2021-11-05 22:56:34 +08:00
Zhidao HONG
1260add0f5 HTTP: removed surplus check for r->args is not NULL. 2021-11-05 11:19:15 +08:00
Zhidao HONG
40ad333a9c Router: fixed nxt_http_route_arguments_parse().
A valid query string argument is a string of "key=value\[&key=value ...\]"
pairs with non-empty keys.  The fix removes invalid empty arguments.
2021-11-05 11:10:03 +08:00
Zhidao HONG
85ab3f5ab5 Configuration: improved matching pattern error messages. 2021-11-05 10:51:41 +08:00
Valentin Bartenev
b6f4b3afb1 Improved logging of app module load errors. 2021-11-02 17:34:23 +03:00
Max Romanov
bba97134e9 Moving request limit control to libunit.
Introducting application graceful stop.  For now only used when application
process reach request limit value.

This closes #585 issue on GitHub.
2021-10-28 17:46:54 +03:00
Max Romanov
803e037302 Python: creating and reusing asgi_add_reader() wrapper. 2021-10-28 17:46:52 +03:00
Max Romanov
86138113eb Adding explicit app reference to nxt_router_app_port_release().
port->app field is not thread safe and should be used in main thread only.
To release port after request processing, application reference should be
obtained from corresponding request descriptor.
2021-10-28 17:46:50 +03:00
Valentin Bartenev
1441f42b5d Fixed memleaks if PID checks fail in nxt_port_incoming_port_mmap().
Memory allocated for "mem" and "mmap_handler" leaked in that case.
Also removed one dead assigment of "hdr" pointer.
2021-10-27 20:37:34 +03:00
Valentin Bartenev
561dbeb98d Fixed a potential descriptor leak if mmap() failed. 2021-10-26 19:31:43 +03:00
Valentin Bartenev
7bf6253941 Custom implementation of Base64 decoding function.
Compared to the previous implementation based on OpenSSL, the new implementation
has these advantages:

 1. Strict and reliable detection of invalid strings, including strings with
    less than 4 bytes of garbage at the end;

 2. Allows to use Base64 strings without '=' padding.
2021-10-26 15:43:44 +03:00
Zhidao HONG
78a4063063 Removed unused declarations.
Declarations became unused after 6976d36be926.

No functional changes.
2021-10-12 10:32:17 +08:00
Zhidao HONG
5fa5b1464f Configuration: automatic migration to the new "share" behavior. 2021-10-09 10:44:31 +08:00
Artem Konev
cdaa8e2523 Fixed invalid call sequence in nxt_tls_ticket_key_callback().
The bug has been introduced in 0bca988e9541.
2021-10-08 13:44:14 +01:00
Valentin Bartenev
8db8330f84 Static: removed surplus assignment.
It's not needed after 69d823e5710a.
Found by Clang Static Analyzer.
2021-10-04 15:33:56 +03:00
Valentin Bartenev
9baf22e7bf Static: fixed possible descriptor leak introduced in a946d8cd7f8c. 2021-10-04 15:33:04 +03:00
Zhidao HONG
95e6535909 Static: multiple paths in the "share" option. 2021-10-01 10:03:55 +08:00
Zhidao HONG
c5220944d2 Static: variables in the "share" option.
This commit supports variable in the "share" option, the finding path to
file serve is the value from "share". An example:
{
    "share": "/www/data/static$uri"
}
2021-09-30 22:17:28 +08:00
Zhidao HONG
37144d6849 Static: variables in the "chroot" option. 2021-09-28 23:08:26 +08:00
Max Romanov
c07f3d3ff6 Fixed WebSocket connection hang issue after listener reconfigure.
Because the configuration values were read from the listener's configuration,
an established WebSocket connection was unable to work properly (i. e. stuck)
if the listener was removed.  The correct source of configuration values is the
request config joint.

This is related to issue #581 on GitHub.
2021-09-20 09:01:08 +03:00
Max Romanov
d21ebcce83 Fixing build with glibc 2.34.
Explicitly using the sysconf() call to obtain the minimum thread stack size
instead of the PTHREAD_STACK_MIN macro.

This closes #576 PR on GitHub.
2021-09-14 19:35:49 +03:00
Zhidao HONG
a336928e10 Router: refactored variable pass.
Since the "pass" option supports both strings and variables, a generic
nxt_var_t structure can be used in the configuration phase, and the "name"
field in actions is redundant.

No functional changes.
2021-09-07 21:13:44 +08:00
Zhidao HONG
9c1894bf77 Var: keeping raw variable string for debug. 2021-09-06 19:27:45 +08:00
Valentin Bartenev
dbc5a742fd TLS: refactored nxt_tls_ticket_key_callback().
Deduplicated code and improved style.
No functional changes.
2021-08-25 10:33:32 +03:00
Andrey Suvorov
e0aa132172 Added TLS session tickets support. 2021-08-17 16:52:32 -07:00
Zhidao HONG
48a9399f23 Introduced the generic API nxt_buf_dummy_completion().
No functional changes.
2021-08-12 17:39:00 +08:00
Zhidao HONG
598f1493f6 Log: renamed related variables "log" as "_log" to prevent conflicts. 2021-08-12 17:41:21 +08:00