summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2019-11-26Changed the group listing to run unprivileged when possible.Tiago Natel1-30/+104
Now the nxt_user_groups_get() function uses getgrouplist(3) when available (except MacOS, see below). For some platforms, getgrouplist() supports a method of probing how much groups the user has but the behavior is not consistent. The method used here consists of optimistically trying to get up to min(256, NGROUPS_MAX) groups; only if ngroups returned exceeds the original value, we do a second call. This method can block main's process if LDAP/NDIS+ is in use. MacOS has getgrouplist(3) but it's buggy. It doesn't update ngroups if the value passed is smaller than the number of groups the user has. Some projects (like Go stdlib) call getgrouplist() in a loop, increasing ngroups until it exceeds the number of groups user belongs to or fail when a limit is reached. For performance reasons, this is to be avoided and MacOS is handled in the fallback implementation. The fallback implementation is the old Unit approach. It saves main's user groups (getgroups(2)) and then calls initgroups(3) to load application's groups in main, then does a second getgroups(2) to store the gids and restore main's groups in the end. Because of initgroups(3)' call to setgroups(2), this method requires root capabilities. In the case of OSX, which has small NGROUPS_MAX by default (16), it's not possible to restore main's groups if it's large; if so, this method fallbacks again: user_cred gids aren't stored, and the worker process calls initgroups() itself and may block for some time if LDAP/NDIS+ is in use.
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-14Python: avoiding buffering of exception backtraces.Valentin Bartenev1-7/+47
A quote from the Python 3 documentation: | When interactive, stdout and stderr streams are line-buffered. | Otherwise, they are block-buffered like regular text files. As a result, if an exception occurred and PyErr_Print() was called, its output could be buffered but not printed to the log for a while (ultimately, until the interpreter finalization). If the application process crashed shortly, the backtrace was completely lost. Buffering can be disabled by redefining the sys.stderr stream object. However, interference with standard environment objects was deemed undesirable. Instead, sys.stderr.flush() is called every time after printing exceptions. A potential advantage here is that lines from backtraces won't be mixed with other lines in the log.
2019-11-14Python: removed wrong PyErr_Print() call.Valentin Bartenev1-1/+0
PyCallable_Check() doesn't produce errors. The needless call was introduced in fdd6ed28e3b9.
2019-11-14Python: optimized response object close() calling.Valentin Bartenev1-7/+14
PyObject_HasAttrString() is just a wrapper over PyObject_GetAttrString(), while PyObject_CallMethod() calls it as the first step. As a result, PyObject_GetAttrString() was called twice if close() was present. To get rid of PyObject_HasAttrString() while keeping the same behaviour, the PyObject_CallMethod() call has been decomposed into separate calls of PyObject_GetAttrString() and PyObject_CallFunction().
2019-11-14Python: fixed an object leak when response close() is called.Valentin Bartenev1-10/+19
On success, PyObject_CallMethod() returns a new reference to the result of the call, which previously got lost. Also, error logging on failure was added. The issue was introduced by b0148ec28c4d.
2019-11-14Python: refactored nxt_python_request_handler().Valentin Bartenev1-56/+31
2019-11-14Python: fixed potential object leak in case of allocation error.Valentin Bartenev1-0/+2
2019-11-14Python: improved error handling if response object isn't iterable.Valentin Bartenev1-0/+1
According to the documentation, PyObject_GetIter(): | Raises TypeError and returns NULL if the object cannot be iterated. Previously, this exception wasn't printed or cleared and remained unhandled.
2019-11-14Python: fixed handling of errors on response object iteration.Valentin Bartenev1-8/+15
According to the documentation, PyIter_Next(): | If there are no remaining values, returns NULL with no exception set. | If an error occurs while retrieving the item, returns NULL and passes | along the exception. Previously, this exception wasn't properly handled and the response was finalized as successful. This issue was introduced in b0148ec28c4d. A check for PyErr_Occurred() located in the code below might print this traceback or occasionally catch an exception from one of the two response close() calls. Albeit that exceptions from the close() calls also need to be catched, it's clear that this particular check wasn't supposed to do so. This is another issue and it will be fixed later.
2019-11-14Processing inconsistent proxied response length.Igor Sysoev4-3/+32
Keepalive connection is disabled if upstream response length differs from specified in the "Content-Length" field value.
2019-11-14Initial proxy support.Igor Sysoev15-44/+1263
2019-11-14Introduced chained buffer completion handlers.Igor Sysoev9-31/+113
2019-11-14Using event engine memory buffers in HTTP/1 layer.Igor Sysoev4-15/+18
2019-11-14Introduced event engine memory buffers.Igor Sysoev4-22/+83
2019-11-14Event engine memory cache refactored.Igor Sysoev3-14/+48
2019-11-14Using request task.Igor Sysoev3-2/+13
2019-11-14Replacing pass with action.Igor Sysoev6-110/+162
2019-11-14Fixed connect(2) errors processing on old Linuxes.Igor Sysoev4-30/+61
While connect(2) states that non-blocking connect should use EPOLLOUT: EINPROGRESS The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure). On connect error, Linux 2.6.32 (CentOS 6) may return EPOLLRDHUP, EPOLLERR, EPOLLHUP, EPOLLIN, but not EPOLLOUT.
2019-11-13Python: releasing GIL while waiting for a request.Valentin Bartenev1-15/+23
It unblocks other threads that can be forked by the application to work in background. This closes #336 issue on GitHub.
2019-11-13Ruby: fixing initialization sequence.Max Romanov1-4/+7
There was a change (ruby/ruby@6c70fed) in Ruby 2.6 that moved RUBY_DESCRIPTION global constant definition out of Init_version(). Unit initialized Ruby incorrectly, so the constant was not defined. This closes #330 issue on GitHub.
2019-11-11Fixing libunit 'off by 2' issue in library.Max Romanov4-16/+27
Name and value in each header are 0-terminated, so additional 2 bytes should be allocated for them. There were several attempts to add these 2 bytes to headers in language modules, but some modules weren't updated. Also, adding these 2 bytes is specific to the implementation which may be changed later, so extending this mechanics to modules may cause errors.
2019-10-29Process port refactoring.Hong Zhi Dao6-67/+65
- Introduced nxt_runtime_process_port_create(). - Moved nxt_process_use() into nxt_process.c from nxt_runtime.c. - Renamed nxt_runtime_process_remove_pid() as nxt_runtime_process_remove(). - Some public functions transformed to static. This closes #327 issue on GitHub.
2019-10-29Allocating process init struct from runtime memory pool.Max Romanov2-17/+14
This avoids memory leak reports from the address sanitizer.
2019-10-28Added clone syscall check for uid/gid mapping.Tiago Natel1-1/+1
Now it's possible to pass -DNXT_HAVE_CLONE=0 for debugging.
2019-10-28Releasing the memory of removed thread pools at exit.Tiago Natel1-0/+2
2019-10-23Python: fixing Python 3.8 build with clang.Max Romanov1-53/+7
Python 3.8 has 'tp_print' field in PyTypeObject struct. This field is attributed as deprecated. So, clang generates warning (which is turned to error) as a result of initializing this field. From the other hand, it is impossible to omit this field in positional initialization. The solution is to use designated initializer. Silencing usage message during configure python. This is related to #331 issue on GitHub.
2019-10-22Improved error logging when uid/gid map is not properly set.Tiago Natel1-2/+30
When using "credential: true", the new namespace starts with a completely empty uid and gid ranges. Then, any setuid/setgid/setgroups calls using ids not properly mapped with uidmap and gidmap fields return EINVAL, meaning the id is not valid inside the new namespace.
2019-10-22Fixing process crash in case of module load error.Max Romanov1-0/+3
This is related to #330 issue on GitHub.
2019-10-22Fixing idle connection close function.Max Romanov1-1/+1
There was a typo: nxt_queue_head() used instead of nxt_queue_first() in connection iteration loop. This prevents idle connection close on quit. This closes #334 issue on GitHub. Thanks to 洪志道 (Hong Zhi Dao).
2019-10-22Python: fixing build for Python 3.8.Max Romanov1-0/+4
Thanks to tonyafanasyev. This is related to #331 issue on GitHub.
2019-10-11Fixed passing false in namespace flags.Tiago Natel3-4/+10
This patch closes #328 in github.
2019-10-10Style fixes.Igor Sysoev7-22/+35
2019-10-10Changed nxt_memcasecmp() interface to avoid casts.Igor Sysoev3-10/+12
2019-10-09Configuration: added check for mandatory options of "action".Valentin Bartenev1-2/+33
2019-10-03Ignoring EINTR error in kqueue.Igor Sysoev1-1/+4
2019-10-02Added response status code to error page body.Valentin Bartenev1-8/+10
Also the error page markup is now valid according to HTML5 specification. All optional tags were omitted.
2019-10-01Go: fixing header buffer size calculation.Max Romanov1-1/+1
Header names and values are stored 0-terminated for ease of use in different languages, so magic number 2 should be added to each name-value pair size.
2019-09-30HTTP: corrected allocation size for tail chunk.Valentin Bartenev1-1/+1
2019-09-30HTTP parser: removed unused "exten" field.Valentin Bartenev3-44/+2
This field was intended for MIME type lookup by file extension when serving static files, but this use case is too narrow; only a fraction of requests targets static content, and the URI presumably isn't rewritten. Moreover, current implementation uses the entire filename for MIME type lookup if the file has no extension. Instead of extracting filenames and extensions when parsing requests, it's easier to obtain them right before serving static content; this behavior is already implemented. Thus, we can drop excessive logic from parser.
2019-09-30HTTP parser: normalization of paths ending with "." or "..".Valentin Bartenev1-8/+28
Earlier, the paths were normalized only if there was a "/" at the end, which is wrong according to section 5.2.4 of RFC 3986 and hypothetically may allow to the directory above the document root.
2019-09-30Fixed error processing in SSL operations.Igor Sysoev1-13/+3
Before this fix EWOULDBLOCK error was fatal for SSL write operation. This closes #325 issue on GitHub.
2019-09-30Fixed exiting if a signal arrives during discovery.Max Romanov1-35/+38
When Unit starts, the main process waits for module discovery message for a while. If a QUIT signal arrives at this time, the router and controller processes created by main and Unit stay running. Also, the main process doesn't stop them after the second QUIT signal is received in this case.
2019-09-26Refactored nxt_process_create() for more explicit pipe closing.Valentin Bartenev1-40/+29
2019-09-26Fixed descriptors leak on process creation.Valentin Bartenev1-0/+12
The leak has been introduced in 325b315e48c4. This closes #322 issue in GitHub.
2019-09-20Removed linux/sched.h include.Tiago Natel1-4/+0
The <sched.h> is already included by nxt_unix.h. This closes #314 PR on GitHub.
2019-09-20Releasing init struct in case of errors.Tiago Natel1-4/+10
Found by Coverity (CID 349485).
2019-09-20Closing leaking file descriptor.Tiago Natel1-0/+4
Found by Coverity (CID 349484).
2019-09-24Static: returning 404 for Unix domain sockets.Valentin Bartenev2-0/+12
It's now similar to how attempts to access other non-regular files are handled.
2019-09-23PHP: zeroing the whole file_handle structure.Sergey Kandaurov1-2/+2
Fixes segfaults with PHP 7.4.