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

Akka.IO bug fixes #3206

Merged
merged 2 commits into from
Dec 3, 2017
Merged

Conversation

Horusiath
Copy link
Contributor

This PR fixes 2 bugs:

  • One is Recursive call in Akka.IO #3203 - a write request was made as part of recursive function call. This could result with StackOverflowException when ratio of written bytes to TCP buffer chunk size was to big (either the bigger the payload or the smaller the direct byte buffer pool could cause this).
  • Another isssue is Akka.IO & WSAEWOULDBLOCK socket error #3188 - when using non-blocking IO, occasionally we could run into non-fatal SocketError.WouldBlock. According to winsock docs, in this case we should try to make a send later. However we could also switch flag to Socket.Blocking = true and fallback to blocking send. This is not ideal, but for sure it's better than the current state.

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.

Looks good to me

try
{
_connection.Socket.Blocking = true;
return _connection.Socket.Send(data.Buffers);
Copy link
Member

Choose a reason for hiding this comment

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

Looks good to me

Copy link

Choose a reason for hiding this comment

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

Guys. Does it mean that connection after that will be "blocking" forever ?

Copy link
Member

Choose a reason for hiding this comment

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

No, only for this operation - on the line below we turn the socket back to non-blocking afterwards in the finally block. Unless the semantics of how this is implemented by the CLR are different than expected...

{
var bytesWritten = _connection.Socket.Send(data.Buffers);
if (_connection.traceLogging)
_connection.Log.Debug("Wrote [{0}] bytes to channel", bytesWritten);
if (bytesWritten < data.Count)
{
// we weren't able to write all bytes from the buffer, so we need to try again later
return WriteToChannel(data.Slice(bytesWritten));
data = data.Slice(bytesWritten);
Copy link
Member

Choose a reason for hiding this comment

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

Looks good

@Aaronontheweb Aaronontheweb merged commit a822003 into akkadotnet:dev Dec 3, 2017
Horusiath added a commit to Horusiath/akka.net that referenced this pull request Dec 4, 2017
* DoWrite changed from recursive function to loop

* workaround for WSAEWOULDBLOCK
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.

3 participants