node icon indicating copy to clipboard operation
node copied to clipboard

server.maxConnections = 0 is treated as if its unset

Open ignoramous opened this issue 1 year ago • 9 comments

server.maxConnections is an Integer, and so, I'd expect 0 to behave the same as -1; ie, drop all incoming conns.

(this is my first commit: I may have messed it up. I skimmed contributing.md but didn't pay much attention to it given this is a straight-forward fix... or, so I think)

ignoramous avatar Jun 01 '23 00:06 ignoramous

Review requested:

  • [ ] @nodejs/net

nodejs-github-bot avatar Jun 01 '23 00:06 nodejs-github-bot

Hello! First of all thanks for your PR. You haven't messed up anything, no worries. The only missing piece is a test to verify this change.

About the subject of the PR itself, I'm a bit conflicted. While you are right in saying that today setting server.maxConnections to 0 or -1 yields a completely different outcome, I'm unsure in what would be the right line of action.

Thinking about the original intent of the flag (and we're talking about Node.js 0.2.0 so it's pretty hard to verify this), I would say to treat 0 and -1 as "feature disabled" rather than "do not accept any connection", as for the latter you can just close the server. So in this case your change would just trim down to:

// ...
if (self.maxConnections > 0 && self._connections >= self.maxConnections) {
// ...

On the other hand, if we want a non strictly positive maxConnections to temporarily prevent the server to accept new connections without having to completely close the server, then your PR is absolutely correct. It will be a breaking change, but not a big deal.

@nodejs/tsc Any opinion on this?

ShogunPanda avatar Jun 02 '23 04:06 ShogunPanda

Yeah, it'd be nice to have 0 and values less than 0 do the same thing (either disable the feature or drop all incoming conns). It is breaking change to do either so some might want to leave it as-is, which I think then needs to go up in the docs. I guess, we can look at how 0 or -ve Integer values in similar Node APIs are treated?

Will amend the code with tests once we reach consensus.

ignoramous avatar Jun 02 '23 07:06 ignoramous

I'm fine with this change. It does need docs and test updates tho.

jasnell avatar Jun 03 '23 16:06 jasnell

It does need docs and test updates tho.

I guess, the docs for behaviour changes are updated at the time of release? If not, let me know what needs to be added to the docs.

I've augmented 2 drop connection tests to account for server.maxConnections = 0.

(My PC isn't capable of building Node and running tests, and so I've enabled the auto-start-ci workflow on my github fork in the hope that it builds Node and runs these tests).

ignoramous avatar Jun 03 '23 20:06 ignoramous

First of all, can you fix the lint problem outlined in the "Files changed tab"? Second, you'll need to edit net.md and change the doc for maxConnections. Before the option you'll find a little YAML changelog you need to edit as well. Use REPLACEME instead of a Node.js version.

ShogunPanda avatar Jun 05 '23 13:06 ShogunPanda

Thanks.

I have no clue what how to proceed.

Second, you'll need to edit net.md and change the doc for maxConnections.

Today, the doc for net.Server.maxConnections is: Set this property to reject connections when the server's connection count gets high. What needs to be edited / changed?

Set this property to reject connections when the server's connection count gets high.
+ Set it to a non-positive number to reject all connections.

Before the option you'll find a little YAML changelog you need to edit as well. Use REPLACEME instead of a Node.js version.

Sorry, I don't get. Is there a previous commit I can look at?

ignoramous avatar Jun 10 '23 07:06 ignoramous

To document it, you should expand the following comment https://github.com/nodejs/node/blob/52758435e1b057e5c1a775f75d2f2facbed57120/doc/api/net.md#L566-L568

with the following:

changes:
  - version: REPLACEME
    pr-url: https://github.com/nodejs/node/pull/48276
    description: Setting `maxConnections` to `0` drops all the incoming
                 connections. Previously it was interpreted as `Infinity`.

Also, can you please run git commit --fixup=reword:3a16de99e78777e98708a7911ea5fe4b9c1ab9d8 and set net: do not treat `server.maxConnections=0` as `Infinity` as the third line? Let me know if you need help with that, I can take care of that for you if you prefer. This is to comply with our commit message guidelines that says it should start with an imperative verb: https://github.com/nodejs/node/blob/260092eca316bae6036e52b2cdc73c4c4f8a9da6/doc/contributing/pull-requests.md#L168-L170

aduh95 avatar Jun 10 '23 08:06 aduh95

changes:

  • version: REPLACEME pr-url: https://github.com/nodejs/node/pull/48276 description: Setting maxConnections to 0 drops all the incoming connections. Previously it was interpreted as Infinity.

Thanks. Changed as mentioned above.

Also, can you please run git commit --fixup=reword:3a16de99e78777e98708a7911ea5fe4b9c1ab9d8 and set net: do not treat server.maxConnections=0 as Infinity as the third line?

I use github.dev for edits and not able to figure out how to run that command. Not enough disk space to checkout Node on my PC, unfortunately.

Let me know if you need help with that, I can take care of that for you if you prefer. This is to comply with our commit message guidelines that says it should start with an imperative verb

Please, feel free to do so.

Thanks a lot (everyone) for being so helpful and patient, despite the fact that I didn't even read contribution guidelines.

ignoramous avatar Jun 21 '23 14:06 ignoramous

CI: https://ci.nodejs.org/job/node-test-pull-request/52407/

nodejs-github-bot avatar Jun 23 '23 19:06 nodejs-github-bot

Hi all,

@nodejs-github-bot node-test-commit — tests failed @nodejs-github-bot node-test-commit-linuxone-rhel8-s390x — tests failed @nodejs-github-bot node-test-pull-request — tests failed

Are the tests I changed failing? Or, is this commit breaking other tests? I clicked on details but unsure if it I should grant it write permissions to my github account?

ignoramous avatar Jun 24 '23 12:06 ignoramous

I think it's an unrelated flaky tests let me try to "resume ci" (run just the failing parts) and see.

benjamingr avatar Jun 24 '23 12:06 benjamingr

CI: https://ci.nodejs.org/job/node-test-pull-request/52426/

nodejs-github-bot avatar Jun 24 '23 14:06 nodejs-github-bot

Landed in 72028594026528f7eb640ebb2807d1a1c7bae172

nodejs-github-bot avatar Jun 26 '23 06:06 nodejs-github-bot

Landed in https://github.com/nodejs/node/commit/72028594026528f7eb640ebb2807d1a1c7bae172

oh my.

ignoramous avatar Jun 26 '23 16:06 ignoramous

Congrats on your first commit on Node.js 🎉

aduh95 avatar Jun 26 '23 16:06 aduh95