Commit Graph

58 Commits

Author SHA1 Message Date
Alejandro Colomar
6e16d7ac5b Auto: mirroring installation structure in build tree.
This makes the build tree more organized, which is good for adding new
stuff.  Now, it's useful for example for adding manual pages in man3/,
but it may be useful in the future for example for extending the build
system to run linters (e.g., clang-tidy(1), Clang analyzer, ...) on the
C source code.

Previously, the build tree was quite flat, and looked like this (after
`./configure && make`):

    $ tree -I src build
    build
    ├── Makefile
    ├── autoconf.data
    ├── autoconf.err
    ├── echo
    ├── libnxt.a
    ├── nxt_auto_config.h
    ├── nxt_version.h
    ├── unitd
    └── unitd.8

    1 directory, 9 files

And after this patch, it looks like this:

    $ tree -I src build
    build
    ├── Makefile
    ├── autoconf.data
    ├── autoconf.err
    ├── bin
    │   └── echo
    ├── include
    │   ├── nxt_auto_config.h
    │   └── nxt_version.h
    ├── lib
    │   ├── libnxt.a
    │   └── unit
    │       └── modules
    ├── sbin
    │   └── unitd
    ├── share
    │   └── man
    │       └── man8
    │           └── unitd.8
    └── var
        ├── lib
        │   └── unit
        ├── log
        │   └── unit
        └── run
            └── unit

    17 directories, 9 files

It also solves one issue introduced in
5a37171f73 ("Added default values for pathnames.").  Before that
commit, it was possible to run unitd from the build system
(`./build/unitd`).  Now, since it expects files in a very specific
location, that has been broken.  By having a directory structure that
mirrors the installation, it's possible to trick it to believe it's
installed, and run it from there:

    $ ./configure --prefix=./build
    $ make
    $ ./build/sbin/unitd

Fixes: 5a37171f73 ("Added default values for pathnames.")
Reported-by: Liam Crilly <liam@nginx.com>
Reviewed-by: Konstantin Pavlov <thresh@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Andrei Zeliankou <zelenkov@nginx.com>
Cc: Zhidao Hong <z.hong@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
2023-03-29 00:41:08 +02:00
Andrei Zeliankou
d862f581db Node.js: added "shortCircuit" option for ES modules hook.
Starting from Node.js v18.6.0 return value from all hooks must have
"shortCircuit: true" option specified.  For more information see:
https://github.com/nodejs/node/commit/10bcad5c6e
2022-12-06 14:30:13 +00:00
Andrew Clayton
b00983369b Renamed a couple of members of nxt_unit_request_t.
This is a preparatory patch that renames the 'local' and 'local_length'
members of the nxt_unit_request_t structure to 'local_addr' and
'local_addr_length' in preparation for the adding of 'local_port' and
'local_port_length' members.

Suggested-by: Zhidao HONG <z.hong@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2022-10-03 14:32:28 +01:00
Andrei Zeliankou
bd80039e07 Node.js: fixed ES modules format in loader.mjs.
Before Node.js v16.14.0 the "format" value in defaultResolve
was ignored so error was hidden.  For more information see:
https://github.com/nodejs/node/pull/40980
2022-06-02 11:48:27 +01: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
1e3f7808b1 Node.js: improving and test packaging.
The patch removes the "files" section from package.json to avoid future issues
with missing files.  For package testing purposes, 'npm pack' is used instead
of plain 'tar' to simulate packaging more accurately.
2021-06-15 10:35:15 +03:00
Max Romanov
fd3558456e Node.js: packaging new loader.js and loader.mjs.
The files loader.js and loader.mjs (introduced in f85b85094541 and 3c551b9721df)
were added to the packaged files list.
2021-06-02 16:14:22 +03:00
Oisin Canty
c160ea11e4 Node.js: renamed "require_shim" to "loader". 2021-05-24 09:01:42 +00:00
Oisin Canty
a0c083af20 Node.js: a shim for overriding "http" and "websocket" modules.
Also added stubs for Server.address()
This was done to prevent crashes in some popular frameworks like express

Supports both CommonJS and the new ES Modules system syntax e.g:

app.js:
const http = require('http')

app.mjs:
import http from "http"

Usage on Node 14.16.x and higher:
{
    "type": "external",
    "processes": {"spare": 0},
    "working_directory": '/project',
    "executable": "/usr/bin/env",
    "arguments": [
        "node",
        "--loader",
        "unit-http/require_shim.mjs"
        "--require",
        "unit-http/require_shim",
        "app.js"
    ]
}

Usage on Node 14.15.x and lower:
{
    "type": "external",
    "processes": {"spare": 0},
    "working_directory": '/project',
    "executable": "/usr/bin/env",
    "arguments": [
        "node",
        "--require",
        "unit-http/require_shim",
        "app.js"
    ]
}
2021-05-12 09:26:55 +00:00
Valentin Bartenev
067c6096e2 Node.js: used distinct placeholder for version in "package.json".
This makes the "sed" instruction simpler and more portable, as the previous
variant didn't work well on BSD systems due to the "\s" metacharacter.

Thanks to Sergey A. Osokin <osa@FreeBSD.org.ru> for spotting this issue.

Also, this should prevent accidentally creating a version 1.0.0 package.
2021-03-25 16:15:03 +03:00
Max Romanov
d65a66f9d8 Libunit: processing single port message.
This partially reverts the optimisation introduced in 1d84b9e4b459 to avoid an
unpredictable block in nxt_unit_process_port_msg().  Under high load, this
function may never return control to its caller, and the external event loop
(in Node.js and Python asyncio) won't be able to process other scheduled
events.

To reproduce the issue, two request processing types are needed: 'fast' and
'furious'.  The 'fast' one simply returns a small response, while the 'furious'
schedules asynchronous calls to external resources.  Thus, if Unit is subjected
to a large amount of 'fast' requests, the 'furious' request processing freezes
until the high load ends.

The issue was found by Wu Jian Ping (@wujjpp) during Node.js stream
implementation discussion and relates to PR #502 on GitHub.
2020-12-29 19:01:24 +03:00
Max Romanov
d3d6864bdc Node.js: ServerRequest and ServerResponse compliance to Stream API.
ServerRequest now inherit stream Readable object.  ServerResponse
provides 'writable' property.

Thanks to Wu Jian Ping (@wujjpp).

This closes #274, closes #317 issues and closes #502 PR on GitHub.
2020-12-29 19:00:54 +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
Max Romanov
55296e6ff2 Node.js: removing unnecessary warnings.
Warnings changed for debug messages.
2020-11-30 23:30:20 +03:00
Max Romanov
6c3c83561a Libunit: closing active requests on quit. 2020-11-18 22:33:53 +03:00
Max Romanov
8359560612 Introducing the shared application port.
This is the port shared between all application processes which use it to pass
requests for processing.  Using it significantly simplifies the request
processing code in the router.  The drawback is 2 more file descriptors per each
configured application and more complex libunit message wait/read code.
2020-08-11 19:20:15 +03:00
Max Romanov
ec3389b63b Libunit refactoring: port management.
- Changed the port management callbacks to notifications, which e. g. avoids
the need to call the libunit function
- Added context and library instance reference counts for a safer resource
release
- Added the router main port initialization
2020-08-11 19:19:55 +03:00
Max Romanov
375cbc2cc4 Node.js: correct port data memory release.
According to libuv documentation, uv_poll_t memory should be released
in a callback function passed to uv_close().  Otherwise, the Node.js application
process may crash at exit.
2020-08-07 15:06:24 +03:00
Max Romanov
ce53d6bdb1 Node.js: fixing Server.listen() method.
This is required for Express framework compatibility.

This closes #418 issue on GitHub.
2020-04-08 14:44:53 +03:00
Max Romanov
004ab48a9e Node.js: fixing x86 warning about the signed/unsigned comparison. 2020-03-03 18:28:16 +03:00
Max Romanov
1451090d85 Node.js: suppress compilation warning. 2020-01-28 17:06:57 +03:00
Max Romanov
763bdff401 Node.js: implementing output message drain using SHM_ACK feature.
ServerResponse.write() method tries to write data buffer using libunit
and stores buffers to write in a Server-wide output queue, which is
processed in response to SHM_ACK message from router.

As a side effect 'drain' event implemented and socket.writable flag
reflect current state.
2019-12-24 18:04:17 +03:00
Max Romanov
f2610d2160 Fixing libunit 'off by 2' issue in library.
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-11-11 18:04:17 +03:00
Max Romanov
e291841b33 Node.js: introducing websocket support. 2019-08-20 16:32:05 +03:00
Valentin Bartenev
7fd9444728 Node.js: returning "this" from writeHead() to allow chaining.
In Node.js version 11.10.0 and later, the writeHead() function returns "this".
2019-08-06 16:24:11 +03:00
Max Romanov
24400b3a5d Node.js: packaging new nxt_napi.h.
File nxt_napi.h (introduced in 53533ba0097c) added into packaged files
list.

This closes #261 issue on GitHub.
2019-06-17 18:16:06 +03:00
Max Romanov
c6e96647a1 Node.js: using low-case header names as key in req.headers.
Node.js modules (body-parser, row-body) search low-cased names
('content-length', 'content-type' etc.) to properly assemble request body.

This closes #246 issue on GitHub.
2019-04-17 19:15:41 +03:00
Valentin Bartenev
7b839bf5da Backed out changeset f74d4dd9c3db.
This closes #240 issue on GitHub.
2019-04-03 18:40:47 +03:00
Max Romanov
6241099db2 Removing unused variables and assignments.
Warnings introduced in 53533ba0097c commit.
2019-04-02 16:07:49 +03:00
Max Romanov
56101e47ee Adding 'connection' to request as an alias to 'socket'.
Adding actual 'remoteAddress' and 'localAddress' into socket object.

This closes #232 issue on GitHub.
2019-04-01 16:40:49 +03:00
Max Romanov
8557cb3660 Introducing close event to notify about server stop.
This closes #236 on GitHub.
Thanks to 0xcdcdcdcd.
2019-04-01 16:40:40 +03:00
Max Romanov
aca42de18a Adding syntax sugar.
With exceptions and overloads.
2019-04-01 16:40:33 +03:00
Andrey Zelenkov
22de5fcddf Style. 2019-03-11 17:31:59 +03:00
Alexander Borisov
608e09e9de Improvement and unification of version processing in build scripts.
This also eliminates expressions that incompatible with BSD make, thus fixing
installation of Node.js module on FreeBSD (broken by dace60fc4926).
2019-02-22 16:31:44 +03:00
Alexander Borisov
98e8f366da Node.js: removed value checking for headers. 2018-12-19 15:57:07 +03:00
Alexander Borisov
d9dad07934 Node.js: removed unused _implicitHeader() function. 2018-12-19 15:57:04 +03:00
Alexander Borisov
d6f38a3268 Node.js: added check for libunit version at compile time. 2018-12-19 15:56:57 +03:00
Alexander Borisov
c55f329ecf libunit: added generation of version header file. 2018-12-19 15:56:54 +03:00
Alexander Borisov
ab461437b5 Node.js: checking for exception after running JS code from C++. 2018-12-19 15:56:37 +03:00
Alexander Borisov
dcf51274ce Node.js: checking uniqueness of HTTP headers for different case. 2018-12-19 15:56:30 +03:00
Alexander Borisov
607653c0f1 Node.js: calling write callback asynchronously. 2018-12-19 15:56:13 +03:00
Alexander Borisov
704fe556b4 Node.js: style fixes.
No functional changes.
2018-12-19 15:56:09 +03:00
Alexander Borisov
dc16885b60 Node.js: changed the unit-http socket constructor.
Third-party file descriptors are not supported.
Socket "readable" and "writable" options are set true by default.
2018-12-19 15:56:06 +03:00
Alexander Borisov
f47a5db506 Node.js: napi_call_function() replaced with napi_make_callback().
The sequence of napi_open_callback_scope(),
napi_call_function(), and napi_close_callback_scope() functions calls
executes the provided JS code and all functions enqueued by
process.nextTick() and Promises during this execution.
2018-12-19 15:56:01 +03:00
Alexander Borisov
13c9ebccca Node.js: changed the 'data' event calling sequence for the request.
The problem is caused by Promises' inconsistency.
The 'date' event could have been triggered before the user has started
listening for it.  To resolve the issue, we override the 'on' method of
the request's emitter.
2018-12-19 15:55:58 +03:00
Alexander Borisov
de3c062c6e Node.js: buffering HTTP headers before writing the body. 2018-12-19 15:55:54 +03:00
Valentin Bartenev
aeb026c8ab Node.js: removed unused dependency. 2018-12-12 19:57:15 +03:00
Valentin Bartenev
2b4d83cbd8 Node.js: npm package readme cleanup. 2018-11-15 15:53:35 +03:00
Alexander Borisov
5c2021f834 Node.js: res.write() must return a bool value. 2018-11-15 14:42:51 +03:00
Alexander Borisov
fb18a09cd7 Node.js: fixed handling of response header fields.
This fixes two issues:

- values for mutiple header fields with the same name
  passed as arrays were converted to string;

- the type of field value wasn't preserved as required
  by specification.
2018-11-15 15:21:52 +03:00