Commit graph

1684 commits

Author SHA1 Message Date
Max Romanov
7b669ed866 Libunit: fixed shared memory waiting.
The nxt_unit_ctx_port_recv() function may return the NXT_UNIT_AGAIN code, in
which case an attempt to reread the message should be made.

The issue was reproduced in load testing with response sizes 16k and up.
In the rare case of a NXT_UNIT_AGAIN result, a buffer of size -1 was processed,
which triggered a 'message too small' alert; after that, the app process was
terminated.
2020-12-18 00:25:28 +03:00
Max Romanov
7389a50835 Limiting app queue notifications count in socket.
Under high load, a queue synchonization issue may occur, starting from the
steady state when an app queue message is dequeued immediately after it has been
enqueued.  In this state, the router always puts the first message in the queue
and is forced to notify the app about a new message in an empty queue using a
socket pair.  On the other hand, the application dequeues and processes the
message without reading the notification from the socket, so the socket buffer
overflows with notifications.

The issue was reproduced during Unit load tests.  After a socket buffer
overflow, the router is unable to notify the app about a new first message.
When another message is enqueued, a notification is not required, so the queue
grows without being read by the app.  As a result, request processing stops.

This patch changes the notification algorithm by counting the notifications in
the pipe instead of getting the number of messages in the queue.
2020-12-18 00:25:27 +03:00
Max Romanov
c0449e13f8 Router: fixed crash in OOSM processing.
Multithreaded application may create different shared memory segments in
different threads.  The segments then passed to different router threads.
Because of this multithreading, the order of adding incoming segments is
not determined and there can be situation when some of the incoming segments
are not initialized yet.

This patch simply adds check for NULL to skip non-initialized segments.

Crash reproduced during load tests with high number of simultaneous
connections (1024 and more).
2020-12-17 19:27:44 +03:00
Andrei Belov
53d847615b Packages: run non-privileged processes under "unit" user. 2020-12-17 14:30:18 +03:00
Konstantin Pavlov
a5fa9673d9 Packages: added pcre2 to build depends.
While at it, propagate unit build depends to modules.
2020-11-24 14:27:06 +03:00
Konstantin Pavlov
9c09bc1772 Packages: dropped support for non-systemd distributions. 2020-11-24 13:25:09 +03:00
Andrei Belov
c33b10a41f Packages: eliminated debuild warning about debian/rules. 2020-12-16 09:56:04 +03:00
Andrei Belov
0c1abda391 Packages: the NOTICE file added to debian binaries.
This resolves the following lintian error:
https://lintian.debian.org/tags/missing-notice-file-for-apache-license.html

While here, changed upstream changelog name to conform with the policy:
https://lintian.debian.org/tags/wrong-name-for-upstream-changelog.html
2020-12-16 09:56:01 +03:00
Andrei Belov
d15acabfc5 Packages: introduced PYTEST_ARGS env variable for test targets.
This is useful for running particular tests, e.g.:
PYTEST_ARGS='test/test_respawn.py::TestRespawn::test_respawn_router' make test
2020-12-16 09:55:59 +03:00
Tiago Natel de Moura
ea5844ae7b Added a changelog for 5e6c2b8fb3fe. 2020-12-15 13:01:44 +00:00
Tiago Natel de Moura
66ac35e9b9 Tests: fixed bug that disabled isolation tests. 2020-12-15 11:06:49 +00:00
Valentin Bartenev
8d65a3303b Python: WSGI environment copying moved out of request processing.
The WSGI environment dictionary contains a number of static items, that are
pre-initialized on application start.  Then it's copied for each request to be
filled with request-related data.

Now this dictionary copy operation will be done between processing of requests,
which should save some CPU cycles during request processing and thus reduce
response latency for non-peak load periods.
2020-12-14 17:15:49 +03:00
Tiago Natel de Moura
1e9def50c8 Isolation: fixed unmounting when mnt namespace is in place.
The code had a wrong assumption that "mount namespaces" automatically
unmounts process mounts when exits but this happens only with
unprivileged mounts.
2020-12-14 12:00:28 +00:00
Andrei Zeliankou
425ffc9416 Tests: hyphen sign used unstead of underscore as more common. 2020-12-12 20:08:03 +00:00
Andrei Zeliankou
16ac829c8f Tests: added tests for PHP_AUTH_* variables. 2020-12-10 19:28:41 +00:00
Andrei Zeliankou
7be62c3c21 Tests: TestUnit class removed.
Prerequisite checks moved to the fixture in conftest.py.
2020-12-09 16:17:46 +00:00
Andrei Zeliankou
4c846ae693 Tests: isolation check moved to the pytest_sessionstart().
This change eliminates the need for some classes
to run Unit one more time before running tests.
2020-12-09 16:15:50 +00:00
Konstantin Pavlov
783cdc2a3d Docker: creating tags and pushing to AWS ECR as well. 2020-12-02 17:33:09 +03:00
Max Romanov
d3796d1fb7 Ruby: fixed crash on thread start.
Ruby threads need to be created with GVL; otherwise, an attempt to access
locked resources may occur, causing a crash.

The issue was occasionally reproduced on Ubuntu 18.04 with Ruby 2.5.1
while running test_ruby_application_threads.
2020-12-07 18:17:25 +00:00
Tiago Natel de Moura
c7bd96b476 Tests: fixed ruby isolation.
While alternating between running priv and unpriv tests
locally, it happens that unpriv tests can't bind mount
or create sub directories inside directories created
by root.  This patch fixes this by pointing "rootfs"
to temporary directory.

Now the priv and unpriv test uses the same test function.
2020-12-08 16:38:41 +00:00
Andrei Zeliankou
b2e767819f Tests: skip_alert() converted to the fixture. 2020-12-08 14:37:33 +00:00
Andrei Zeliankou
8f91628563 Tests: utils module introduced. 2020-12-08 14:37:25 +00:00
Andrei Belov
12a0d259a5 Docs: special handling for empty "date" and "time" XML attributes. 2020-12-08 13:17:21 +03:00
Valentin Bartenev
2348229dc7 PHP: populating PHP_AUTH_* server variables.
This closes #498 issue on GitHub.
2020-12-08 01:59:46 +03:00
Valentin Bartenev
bda76b04e9 HTTP: fixed status line format for unknown status codes.
According to Section #3.1.2 of RFC 7230, after the status code
there must be a space even if the reason phrase is empty.

Also, only 3 digits allowed.

This closes #507 issue on GitHub.
2020-12-07 18:50:56 +03:00
Max Romanov
db42527b1b Node.js: avoided use of request struct for debug logging.
This fixes a crash on exit of Node.js application.  The crash reproduced
on Ubuntu 20.10 with Node.js v15.1.0.  Tests 'test_node_websockets_two_clients'
and 'test_node_websockets_7_13_1__7_13_2'.

The reason of the crash is using request struct which was already freed.

The issue was introduced in 5be509fda29e.
2020-12-07 17:56:18 +03:00
Andrei Zeliankou
07789a23e9 Tests: options moved to the separate class.
This change is necessary to separate the logic
and prevent possible circular dependency.
2020-12-06 16:01:59 +00:00
Max Romanov
55296e6ff2 Node.js: removing unnecessary warnings.
Warnings changed for debug messages.
2020-11-30 23:30:20 +03:00
Valentin Bartenev
956fce6614 Libunit: improved error logging around initialization env variable. 2020-11-24 16:40:35 +03:00
Valentin Bartenev
35178dbb06 Version bump. 2020-11-24 16:40:28 +03:00
Valentin Bartenev
806a9b2515 Added tag 1.21.0 for changeset f804aaf7eee1 2020-11-19 21:13:19 +03:00
Valentin Bartenev
9e85732e9a Generated Dockerfiles for Unit 1.21.0. 2020-11-19 21:12:30 +03:00
Valentin Bartenev
fa1a3298ef Added version 1.21.0 CHANGES. 2020-11-19 19:59:18 +03:00
Axel Duch
e3af18834d Router: matching regular expressions support. 2020-11-17 15:03:30 +00:00
Max Romanov
2a381a82a6 Libunit: fixing read buffer leakage.
If shared queue is empty, allocated read buffer should be explicitly
released.

Found by Coverity (CID 363943).
The issue was introduced in f5ba5973a0a3.
2020-11-19 13:49:12 +03:00
Andrei Zeliankou
18ddb74772 Tests: added tests for a "discard_unsafe_fields" option. 2020-11-19 05:21:48 +00:00
Andrei Zeliankou
e154d7a3a2 Tests: style. 2020-11-19 05:21:22 +00:00
Max Romanov
25219a7ece Python: improving ASGI http send message processing. 2020-11-18 22:33:53 +03:00
Max Romanov
66bb41e8bb Libunit: fixing read buffer allocations on exit. 2020-11-18 22:33:53 +03:00
Max Romanov
6c3c83561a Libunit: closing active requests on quit. 2020-11-18 22:33:53 +03:00
Max Romanov
300347a5cf Libunit: making minor tweaks.
Removing unnecessary context operations from shared queue processing loop.
Initializing temporary queues only when required.
2020-11-18 22:33:53 +03:00
Max Romanov
8132e1f700 Go: removing C proxy functions and re-using goroutines. 2020-11-18 22:33:53 +03:00
Max Romanov
d26afcb481 Libunit: fixing racing condition in request struct recycling.
The issue occurred under highly concurrent request load in Go applications.
Such applications are multi-threaded but use a single libunit context; any
thread-safe code in the libunit context is only required for Go applications.

As a result of improper request state reset, the recycled request structure was
recovered in the released state, so further operations with this request
resulted in 'response already sent' warnings.  However, the actual response was
never delivered to the router and the client.
2020-11-18 22:33:53 +03:00
Max Romanov
0ec69aa46e Libunit: fixing racing condition for port add / state change.
The issue only occurred in Go applications because "port_send" is overloaded
only in Go.  To reproduce it, send multiple concurrent requests to the
application after it has initialised.  The warning message "[unit] [go] port
NNN:dd not found" is the first visible aspect of the issue; the second and more
valuable one is a closed connection, an error response, or a hanging response to
some requests.

When the application starts, it is unaware of the router's worker thread ports,
so it requests the ports from the router after receiving requests from the
corresponding router worker threads.  When multiple requests are processed
simultaneously, the router port may be required by several requests, so request
processing starts only after the application receives the required port
information.  The port should be added to the Go port repository after its
'ready' flag is updated.  Otherwise, Unit may start processing some requests and
use the port before it is in the repository.

The issue was introduced in changeset 78836321a126.
2020-11-18 22:33:53 +03:00
Max Romanov
8340ca0b9c Libunit: improving logging consistency.
Debug logging depends on macros defined in nxt_auto_config.h.
2020-11-18 22:33:53 +03:00
Valentin Bartenev
fb80502513 HTTP parser: allowed more characters in header field names.
Previously, all requests that contained in header field names characters other
than alphanumeric, or "-", or "_" were rejected with a 400 "Bad Request" error
response.

Now, the parser allows the same set of characters as specified in RFC 7230,
including: "!", "#", "$", "%", "&", "'", "*", "+", ".", "^", "`", "|", and "~".
Header field names that contain only these characters are considered valid.

Also, there's a new option introduced: "discard_unsafe_fields".  It accepts
boolean value and it is set to "true" by default.

When this option is "true", all header field names that contain characters
in valid range, but other than alphanumeric or "-" are skipped during parsing.
When the option is "false", these header fields aren't skipped.

Requests with non-valid characters in header field names according to
RFC 7230 are rejected regardless of "discard_unsafe_fields" setting.

This closes #422 issue on GitHub.
2020-11-17 16:50:06 +03:00
Tiago Natel de Moura
e7d66acda7 Isolation: added option to disable "procfs" mount.
Now users can disable the default procfs mount point
in the rootfs.

 {
     "isolation": {
         "automount": {
             "procfs": false
         }
     }
 }
2020-11-16 17:56:12 +00:00
Tiago Natel de Moura
bbc29df8fe Tests: tmpfs automount. 2020-11-16 17:22:10 +00:00
Max Romanov
567f0a7b30 Tests: fixing tests interrupt in terminal.
KeyboardInterrupt re-raised.
2020-11-16 20:37:01 +03:00
Max Romanov
6d2b60ff3e Tests: making available versions unique. 2020-11-16 20:36:54 +03:00