Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

StreamSocketOutput WriteAsync as async (SSL) #588

Merged
merged 2 commits into from
Apr 27, 2016

Conversation

@benaadams benaadams changed the title StreamSocketOutput WriteAsync as async [Blocked] StreamSocketOutput WriteAsync as async Jan 18, 2016
@benaadams
Copy link
Contributor Author

One half dotnet/corefx#5505 though I think it actually needs the ReadAsync also (as a bidirectional stream and I saw blocking on Read)

@benaadams
Copy link
Contributor Author

Also this is relevant dotnet/coreclr#2724

}
if (!endTask.IsCompleted)
{
return endTask;
Copy link
Member

Choose a reason for hiding this comment

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

Is it wrong to simply return endTask if it's not completed? Will it ever complete prior to preambleTask or dataTask?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, no

block = _producingBlock;
while (block != end.Block)
{
_outputStream.WriteAsync(block.Data.Array, block.Data.Offset, block.Data.Count, CancellationToken.None);
Copy link
Member

Choose a reason for hiding this comment

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

What if the wrapping stream produces an async error? I think we have to await.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will have to await them one after another too as don't know the characteristics of the underlying stream; and each write will be sent with immediate:true ;-(

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. It's kinda sad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also means have to do .GetAwaiter().GetResult() else the function may return in an await point... but will only be one.

@benaadams benaadams changed the title [Blocked] StreamSocketOutput WriteAsync as async [Unblocked] StreamSocketOutput WriteAsync as async Jan 22, 2016
@benaadams
Copy link
Contributor Author

Last item dotnet/corefx#5541 has just been merged - will need feed update

@benaadams benaadams force-pushed the async-write branch 2 times, most recently from 4eb8f90 to 8aa5dd0 Compare January 24, 2016 15:18
@benaadams benaadams changed the title [Unblocked] StreamSocketOutput WriteAsync as async [Blocked] StreamSocketOutput WriteAsync as async Jan 26, 2016
@benaadams
Copy link
Contributor Author

Still an issue here - investigating

@muratg
Copy link
Contributor

muratg commented Feb 4, 2016

👀

@benaadams
Copy link
Contributor Author

@muratg this is something I really want - however there have been so many strange issues with it all the way down to coreclr and cross framework; I wouldn't feel confident with it going in rushed - maybe an item to pair with WebSockets timeline? (as the current workaround does work, with caveats)

@benaadams
Copy link
Contributor Author

e.g. backlog

@muratg muratg added this to the Backlog milestone Feb 4, 2016
@cesarblum
Copy link
Contributor

What are we doing with this? Is it still blocked on corefx?

@benaadams
Copy link
Contributor Author

It was still jamming when I last tried it; but I haven't had time to debug to find the problem. SslStream doesn't implement true xxxAsync methods but uses the Stream's BeginAsync/EndAsync.

A change was made to corefx so these methods didn't become sync in coreclr with read and write blocking each other - however I don't think that entirely fixed the issue and I observed something similar happening in full framework.

However; that may have just been a point in time feed issue.

@benaadams
Copy link
Contributor Author

Looks like this might be the final blocker dotnet/corefx#7800

@benaadams benaadams changed the title [Blocked] StreamSocketOutput WriteAsync as async [Blocked] StreamSocketOutput WriteAsync as async (SSL) Apr 18, 2016
@benaadams
Copy link
Contributor Author

benaadams commented Apr 18, 2016

Rebased, still waiting for dotnet/corefx#7800 and/or dotnet/corefx#7819 to hit the feed to likely work

{
_outputStream.Write(block.Data.Array, block.Data.Offset, block.Data.Count);
ProducingCompleteAsync(end).GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's better not to wait for the writes to complete in ProducingComplete. The real SocketOutput.ProducingComplete doesn't block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its a sync memory write though? Issue is the unknown stream type

Copy link
Member

Choose a reason for hiding this comment

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

The main difference is that the real ProducingComplete would never wait for the write behind buffer to flush. This might by waiting for the Task returned by SocketOutput.WriteAsync. It's a difference in behavior that we probably don't account for in the calling code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

block = _producingBlock;
while (block != end.Block)
Copy link
Member

@halter73 halter73 Apr 18, 2016

Choose a reason for hiding this comment

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

I like this way of ensuring blocks are returned better than the _canWrite flag in #750

Copy link
Contributor

Choose a reason for hiding this comment

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

The purpose of _canWrite is to prevent further attempts to call Write().

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

@benaadams
Copy link
Contributor Author

Probably needs to rebase on #750 as this is waiting for a corefx fix to hit the feeds

@cesarblum
Copy link
Contributor

@benaadams #750 now in.

@benaadams
Copy link
Contributor Author

Issue on full framework (block)

Checking coreclr

@benaadams
Copy link
Contributor Author

Works on coreclr; have ifdef'd for full framework

Raise issue for full framework?

@benaadams benaadams changed the title [Blocked] StreamSocketOutput WriteAsync as async (SSL) StreamSocketOutput WriteAsync as async (SSL) Apr 25, 2016
@benaadams
Copy link
Contributor Author

Issue raised for full framework #768

var beginChunkBytes = ChunkWriter.BeginChunkBytes(buffer.Count);

await _outputStream.WriteAsync(beginChunkBytes.Array, beginChunkBytes.Offset, beginChunkBytes.Count, cancellationToken);
await _outputStream.WriteAsync(buffer.Array ?? _nullBuffer, buffer.Offset, buffer.Count, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

buffer.Array ?? _nullBuffer: the coalescing part of this expression will never be hit. buffer.Array is checked in WriteAsync

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True :)

@cesarblum
Copy link
Contributor

Bummer that it doesn't work on desktop clr, but that's better than nothing 😄

:shipit:

@cesarblum cesarblum merged commit 216aa93 into aspnet:dev Apr 27, 2016
@benaadams benaadams deleted the async-write branch May 10, 2016 10:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants