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

[Async TestKit] Modernize TcpStage and TcpListener #5989

Merged
merged 5 commits into from Jun 10, 2022

Conversation

Arkatufus
Copy link
Contributor

Changes:
Make TcpListener binding and unbinding code non-blocking by running them on another thread.

@Arkatufus Arkatufus changed the title Modernize TcpStage and TcpListener [Async TestKit] Modernize TcpStage and TcpListener Jun 10, 2022
Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Missing API approval

public static WritingResumed Instance = new WritingResumed();
public static readonly WritingResumed Instance = new WritingResumed();

private WritingResumed()
Copy link
Member

Choose a reason for hiding this comment

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

These are breaking API changes, but no big deal. Need to be able to do stuff like this in Akka.NET v1.5.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Left some feedback

try
{
bind.Options.ForEach(x => x.BeforeServerSocketBind(_socket));
_socket.Bind(bind.LocalAddress);
Copy link
Member

Choose a reason for hiding this comment

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

Good idea, moving this out of the constructor

_binding = true;
_bind = bind;
_acceptLimit = bind.PullMode ? 0 : _tcp.Settings.BatchAcceptLimit;
BindAsync().PipeTo(Self);
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

if (!_socket.AcceptAsync(saea))
Self.Tell(new SocketEvent(saea));
return true;

case Tcp.ResumeAccepting resumeAccepting:
_acceptLimit = resumeAccepting.BatchSize;
// TODO: this is dangerous, previous async args are not disposed and there's no guarantee that they're not still receiving data
Copy link
Member

Choose a reason for hiding this comment

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

Previous socket async event args?

Copy link
Contributor Author

@Arkatufus Arkatufus Jun 10, 2022

Choose a reason for hiding this comment

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

_saeas is an array of SocketAsyncEventArgs, assigned by the Accept method.
In this case, the old code actually discarded all of the old args while most of them still active accepting connections, we would lose all reference to those event args.

  1. They cause a memory leak, or
  2. They can get finalized and disposed and something breaks.

Copy link
Member

Choose a reason for hiding this comment

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

aren't these SAEA only handling bind events though, which have no buffers?

src/core/Akka/IO/TcpListener.cs Show resolved Hide resolved
@Aaronontheweb Aaronontheweb added this to the 1.5.0 milestone Jun 10, 2022
@Aaronontheweb Aaronontheweb merged commit 8f960ff into akkadotnet:dev Jun 10, 2022
@Arkatufus Arkatufus deleted the async_testkit/Modernize_TCP branch February 27, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants