Skip to content
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: Force closes bad connections #2033

Closed
wants to merge 2 commits into from

Conversation

kamronbatman
Copy link
Contributor

No description provided.

Copy link

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Detected 20 dependencies

Third-party software list

This page lists the third-party software dependencies used in ModernUO

Dependency Version Licenses
Argon2.Bindings 1.16.1 MIT
BouncyCastle.Cryptography 2.5.0 MIT
CommunityToolkit.HighPerformance 8.4.0 MIT
LibDeflate.Bindings 1.0.2.120 GPL-3.0-only
MailKit 4.9.0 MIT
Microsoft.Extensions.FileSystemGlobbing 9.0.0 MIT
MimeKit 4.9.0 MIT
ModernUO.CodeGeneratedEvents.Annotations 1.0.0 GPL-3.0-only
ModernUO.CodeGeneratedEvents.Generator 1.0.3.2 GPL-3.0-only
ModernUO.Serialization.Annotations 2.9.1 GPL-3.0-only
ModernUO.Serialization.Generator 2.12.18 GPL-3.0-only
Nerdbank.GitVersioning 3.7.112 MIT
PollGroup 1.6.1 BSD-3-Clause
Serilog.Sinks.Async 2.1.0 Apache-2.0
Serilog.Sinks.Console 6.0.0 Apache-2.0
Serilog 4.2.0 Apache-2.0
System.Formats.Asn1 8.0.1 MIT
System.IO.Hashing 9.0.0 MIT
System.Security.Cryptography.Pkcs 8.0.1 MIT
Zstd.Binaries 1.6.0 MIT
Contact Qodana team

Contact us at [email protected]

var firstBytes = new byte[5];
try
{
await socket.ReceiveAsync(firstBytes, SocketFlags.Peek).WaitAsync(TimeSpan.FromMilliseconds(20));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Timeout so short won't work

Copy link
Contributor

Choose a reason for hiding this comment

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

After some testing, 30 second timeout (30000) seems better. You can work your way down from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would want the server to wait the least amount of time between accept and first packet to minimize threat surface from DDoS.

Copy link
Contributor

@Bohicatv Bohicatv Dec 28, 2024

Choose a reason for hiding this comment

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

You can close bad connections on the network/firewall side by changing the TCP timeouts there to a 1 to 2 second threshold. The thing with TCP, its error checking, so you want the network/firewalls layer to cut off bad connections so MUO isn't doing most of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that this should definitely be configured outside of the game server. I believe the time out is set by the socket options as well in the code. And by default it never times out. I'm not sure if this overrides the operating system though?

@kamronbatman kamronbatman marked this pull request as draft December 30, 2024 08:16
@kamronbatman
Copy link
Contributor Author

This code won't work the way I want it to. I have a version of this that uses another epoll instance (wepoll on Windows), but due to a bug in wepoll, I won't be able to do "clever' things the way I want to.

I may come around to a deep dive into wepoll so I can fix the bug, but I am not set up (nor do I have the requisite knowledge at this time) to figure it out. cc @jaedan if you are interested in fixing the wepoll bug.

Closing this for now and expect users that need to close bad connections to use a proxy in front of MUO.

@kamronbatman kamronbatman deleted the kbatman/force_close_bad_connections branch December 31, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants