Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

feat: close server on maxConnections #218

Merged
merged 5 commits into from
Jan 20, 2023

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Oct 7, 2022

More resilient strategy to #213 which blocks new connections at the OS layer instead of at the app layer. Both features should exist since each has different tradeoffs. The approach of this PR is necessary for critical apps like Lodestar in highly adversarial environments. #213 is good for less critical situations, where the added complexity is not justified.

@achingbrain
Copy link
Member

This is critical behaviour - please can you add some tests to ensure regressions to not creep in.

@dapplion
Copy link
Contributor Author

dapplion commented Oct 7, 2022

This is critical behaviour - please can you add some tests to ensure regressions to not creep in.

@achingbrain
Copy link
Member

achingbrain commented Oct 11, 2022

#214 is merged, this branch needs a rebase or otherwise master merging into it.

@dapplion dapplion force-pushed the dapplion/close-server branch 3 times, most recently from ae1ffdb to 507c19d Compare October 14, 2022 19:03
@dapplion
Copy link
Contributor Author

@achingbrain Rebased + added unit test

src/index.ts Outdated Show resolved Hide resolved
src/listener.ts Outdated
@@ -25,15 +26,27 @@ async function attemptClose (maConn: MultiaddrConnection) {
}
}

export interface LimitServerConnectionsOpts {
acceptBelow: number
rejectAbove: number
Copy link
Contributor Author

@dapplion dapplion Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rejectAbove: number
/** Server listens once connection count is less than `listenBelow` */
listenBelow: number
/** Close server once connection count is greater or equal than `closeAbove` */
closeAt: number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On constructor sanity check that closeAbove >= listenBelow

src/listener.ts Outdated
interface Context extends TCPCreateListenerOptions {
handler?: (conn: Connection) => void
upgrader: Upgrader
socketInactivityTimeout?: number
socketCloseTimeout?: number
maxConnections?: number
limitServerConnections?: LimitServerConnectionsOpts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
limitServerConnections?: LimitServerConnectionsOpts
closeServerOnMaxConnections?: LimitServerConnectionsOpts

@mpetrunic mpetrunic added the need/author-input Needs input from the original author label Nov 8, 2022
@p-shahi
Copy link
Member

p-shahi commented Nov 22, 2022

@dapplion Any updates on this?

@dapplion
Copy link
Contributor Author

dapplion commented Dec 4, 2022

@dapplion Any updates on this?

Good to go

@mpetrunic
Copy link
Member

@dapplion Any updates on this?

Good to go

There is a type error (CI failling)

@p-shahi
Copy link
Member

p-shahi commented Dec 6, 2022

@achingbrain do we want this in 0.41.0 ?

@p-shahi
Copy link
Member

p-shahi commented Jan 10, 2023

Is this good to merge @dapplion @mpetrunic ?

@achingbrain
Copy link
Member

@wemeetagain is going to test this change under load and merge it if all is well.

@wemeetagain
Copy link
Member

Ran this on a lodestar node, it works well.

@wemeetagain wemeetagain merged commit bff54fa into libp2p:master Jan 20, 2023
@dapplion dapplion deleted the dapplion/close-server branch January 21, 2023 04:31
github-actions bot pushed a commit that referenced this pull request Jan 21, 2023
## [6.1.0](v6.0.9...v6.1.0) (2023-01-21)

### Features

* close server on maxConnections ([#218](#218)) ([bff54fa](bff54fa))

### Bug Fixes

* specify host explicitly in node tests ([#247](#247)) ([d7e5a69](d7e5a69))
@github-actions
Copy link

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/author-input Needs input from the original author released
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants