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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/core/Akka/IO/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,15 +830,17 @@ public override PendingWrite DoWrite(ConnectionInfo info)
{
try
{
PendingWrite WriteToChannel(ByteString data)
var data = _buffer;
while(true)
{
var bytesWritten = _connection.Socket.Send(data.Buffers);
var bytesWritten = Send(data);

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

}
else // finished writing
{
Expand All @@ -848,8 +850,6 @@ PendingWrite WriteToChannel(ByteString data)
}
}

return WriteToChannel(_buffer);

}
catch (SocketException e)
{
Expand All @@ -858,6 +858,26 @@ PendingWrite WriteToChannel(ByteString data)
}
}

private int Send(ByteString data)
{
try
{
return _connection.Socket.Send(data.Buffers);
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.WouldBlock)
{
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...

}
finally
{
_connection.Socket.Blocking = false;
}
}
}

public override void Release() { }
}
}
Expand Down