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

WIP: Improve Async Paths #335

Closed
wants to merge 2 commits into from
Closed

Conversation

benaadams
Copy link
Member

Override other Stream Async methods
Catch exceptions and wrap in Task incase thrown synchronously

contributes to #262

// Account for split packets
while (readBytes < TdsEnums.HEADER_LEN)
{
readBytes += async ?
Copy link
Contributor

Choose a reason for hiding this comment

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

This can infinite loop if the connection is closed and the read returns 0 and doesn't throw, Are closed connections guaranteed to throw or return non-zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... the existing loop also has this issue.

Will fix in both. Good spot

Copy link
Contributor

Choose a reason for hiding this comment

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

Someone else mentioned it elsewhere before I just haven't got around to looking at it in any depth yet so since you're here anyway I thought it worth mentioning.

There may not be a clear way to "fix" it from what I remember. I'm not sure what should happen if you end up in a partial packet read because it's below ssl stream which is going to try and decode anything you return in the buffer which can error that looks like a transport error when in fact it's connection closed. See what you think.

@Wraith2
Copy link
Contributor

Wraith2 commented Dec 3, 2019

Looks good apart from one query on preexisting code pattern.

@cheenamalhotra
Copy link
Member

@benaadams

I believe work is in progress, if it's taking longer to fix the issue we might wanna consider reverting the previous PR to resolve deadlocks for end users, specially in System.Data.SqlClient as they might be preparing for next release in January, also here in Microsoft.Data.SqlClient for users impacted and our next planned preview release is in January.

And with this PR (once we get the fix working) we can introduce the previous changes again.

@benaadams
Copy link
Member Author

yes, its probably best to just reverse the changes if that resolves the issue

cheenamalhotra added a commit to cheenamalhotra/SqlClient that referenced this pull request Dec 11, 2019
cheenamalhotra added a commit that referenced this pull request Dec 13, 2019
@cheenamalhotra cheenamalhotra changed the title Improve Async Paths WIP: Improve Async Paths Dec 13, 2019
catch (Exception ex)
{
t = Task.FromException<int>(ex);
}

if ((t.Status & TaskStatus.RanToCompletion) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

The old code (t.Status & TaskStatus.RanToCompletion) != 0 in SNIPacket.NetStandard.cs looks strange, since TaskStatus is not a flag, so this will even be true for TaskStatus.WaitingForActivation, maybe it should be t.Status == TaskStatus.RanToCompletion instead to follow the logic in netcoreapp?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch. Looking at the enum values that'll let fault and cancel through. I'm surprised visual studio doesn't complain about doing bitwise operations on a non-[Flag] enum.

catch (Exception ex)
{
t = Task.FromException(ex);
}

if ((t.Status & TaskStatus.RanToCompletion) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

And also for this one

@Wraith2 Wraith2 mentioned this pull request Apr 26, 2020
Base automatically changed from master to main March 15, 2021 17:54
@JRahnama
Copy link
Contributor

Closing as it seems this PR is not mergeable due to some deep changes on the main branch. Feel free to open a new PR.

@JRahnama JRahnama closed this Jun 26, 2024
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.

5 participants