-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Take options as well as requestListener #1091
Conversation
I tested with the following nodejs application file at const http = require("http");
const host = 'localhost';
const port = 8000;
const requestListener = function (req, res) {
res.writeHead(200);
res.end("My first server!");
};
const options = {
keepAlive: true
};
const server = http.createServer(options, requestListener);
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
}); and the following unit configuration file: {
"listeners": {
"*:5555": {
"pass": "routes/main"
}
},
"routes": {
"main": [
{
"action": {
"pass": "applications/app"
}
}
]
},
"applications": {
"app": {
"type": "external",
"working_directory": "/Users/g.javorszky/Projects/Unit/issue-1043/flob/",
"executable": "/usr/bin/env",
"arguments": [
"/Users/g.javorszky/.nvm/versions/node/v20.9.0/bin/node",
"--loader",
"/Users/g.javorszky/.nvm/versions/node/v20.9.0/lib/node_modules/unit-http/loader.mjs",
"--require",
"/Users/g.javorszky/.nvm/versions/node/v20.9.0/lib/node_modules/unit-http/loader",
"index.js"
]
}
}
} I had to use absolute paths for the node executable and the two loader files. Given these, navigating to |
c0df715
to
48421f8
Compare
48421f8
to
52550b1
Compare
@andrey-zelenkov I added the docs to changes in cdf9bfe as a response to your comment on the issue here: #1013 (comment) Everyone, let me know if the wording is appropriate, or I should tweak it. |
cdf9bfe
to
e14ed7d
Compare
db4691e
to
7926d1e
Compare
For
I would rather the
|
Only want to approve the first patch not the whole thing.
7926d1e
to
6f624dd
Compare
@andrey-zelenkov I added the test, and in that I'm checking that the log DOES have the log line added, and the test passes for me locally. I have not changed any of the other tests. |
ceb564c
to
e96eabc
Compare
Currently this patch breaks our nodejs module on RHEL8:
If you send request to nodejs app it will fail with 503:
Error message from unit.log:
From my side, I can suggest just dropping error reporting (that uses |
fyi, applying this diff fixes the problem: --- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -5,7 +5,6 @@
'use strict';
-const { stderr } = require('node:process');
const EventEmitter = require('events');
const http = require('http');
const util = require('util');
@@ -418,8 +417,6 @@ function Server(options, requestListener
if (typeof options === 'function') {
requestListener = options;
options = {};
- } else {
- stderr.write("http.Server constructor was called with unsupported options, using default settings\n");
}
EventEmitter.call(this);
diff --git a/test/test_node_application.py b/test/test_node_application.py
--- a/test/test_node_application.py
+++ b/test/test_node_application.py
@@ -21,11 +21,10 @@ def test_node_application_basic():
assert_basic_application()
-def test_node_application_options(wait_for_record):
+def test_node_application_options():
client.load('options')
assert_basic_application()
- assert wait_for_record(r'constructor was called with unsupported') is not None
def test_node_application_loader_unit_http(): |
What version of Node is in use on RHEL 8? |
Whatever it is, I'd expect |
Sorry, forgot most important part:
|
Awesome, thank you for providing that :) Using Separately, we should consider this case when discussing supported platforms. Node 10 has been end-of-life for nearly three years, and even RedHat won't provide paid support for it (or v12 or v14) on RHEL. For those customers, the oldest commercially supported version is Node 16 on RHEL 8.7 or greater. |
That works! |
e96eabc
to
3084881
Compare
For the first patch please put the
|
Unit-http have not kept up with the signature of nodejs's http package development. Nodejs allows an optional `options` object to be passed to the `createServer` function, we didn't. This resulted in function signature errors when user code that did make use of the options arg tried to call unit's replaced function. This change changes the signature to be more in line with how nodejs does it discarding it and printing a message to stdout. Closes: nginx#1043
3084881
to
9dafbdc
Compare
Heh, during all the discussion about |
* Take options as well as requestListener Unit-http have not kept up with the signature of nodejs's http package development. Nodejs allows an optional `options` object to be passed to the `createServer` function, we didn't. This resulted in function signature errors when user code that did make use of the options arg tried to call unit's replaced function. This change changes the signature to be more in line with how nodejs does it discarding it and printing a message to stdout. * Add test file to start node application with options * Add changes to docs/changes.xml Closes: #1043
* Take options as well as requestListener Unit-http have not kept up with the signature of nodejs's http package development. Nodejs allows an optional `options` object to be passed to the `createServer` function, we didn't. This resulted in function signature errors when user code that did make use of the options arg tried to call unit's replaced function. This change changes the signature to be more in line with how nodejs does it discarding it and printing a message to stdout. * Add test file to start node application with options * Add changes to docs/changes.xml Closes: nginx#1043
Closes #1043
Unit-http have not kept up with the signature of nodejs's http package development. Nodejs allows an optional
options
object to be passed to thecreateServer
function, we didn't. This resulted in function signature errors when user code that did make use of the options arg tried to call unit's replaced function.This change changes the signature to be more in line with how nodejs does it discarding it and printing a message to stderr so it shows up in unit logs.