-
Notifications
You must be signed in to change notification settings - Fork 286
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
Add partial packet detection and fixup #2714
base: main
Are you sure you want to change the base?
Conversation
I've added comments to the Packet class as requested. The CI was green apart from some ubuntu legs which timed out, many other ubuntu legs succeeded so I don't see any direct inference on from that. Ready for review @David-Engel @saurabh500 @cheenamalhotra |
@Wraith2 We are reviewing this and hope to get faster traction towards EOW. |
Pasting test failure for reference:
This test should be looked at carefully. It failed on Ubuntu with .NET 6 and 8 , and also hung up on Windows when ran with Managed SNI, link to logs 1 link to logs 2. @Wraith2 can you confirm if this is something you're able to repro in Windows with Managed SNI? Please make sure config file is configured to enable Managed SNI on Windows. |
{ | ||
// Do nothing with callback if closed or broken and error not 0 - callback can occur | ||
// after connection has been closed. PROBLEM IN NETLIB - DESIGN FLAW. | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a Debug Assert here and check if this is taking any hit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test needs to be fixed, before reviewing any further.
Isn't this the set of tests that @David-Engel pointed out in #2608 (comment) ? If so we discussed it at length on the teams call. I don't believe that those tests are reliable. Setup a breakpoint or Debug.WriteLine where an exception is added to the state object and run the test. You should find that an exception is always added to the state object but that the test will usually succeed. That should not be possible, an exception if added should be thrown. The test is missing failures and if that's the case then the test is unreliable. |
When you work past the terrible code in SNITCPHandle and make the test run for long enough it settles into a steady state where it can't reach the end. There is no indication why yet.
those 9 in flight items just don't seem to complete but i don't know why. |
After a few more hours investigation I know what the problem is but I have no clue what change has caused it. In SqlDataReader when an async method is called we use a context object to contain some state and pass that context object to all the async methods that are used to implement the async read machinery. Part of this state is the TaskCompletionSource. What I don't understand is how cancel is supposed to work. I'm unable to run the tests in native sni mode because the native sni can't be initialized (can't find the sni dll). So I can't compare the managed to unmanaged implementations here. I don't believe that I have made any change that should affect cancellation. I have verified that there are no partial packets in the state objects when the async tasks get stuck. I don't understand how async cancellation is supposed to work at all. |
88fbb93
to
8b57818
Compare
Can someone with CI access rerun the failed legs? the failures are random or CI resources not being available as far as i can tell. |
The current failures are interesting. They're in the test that was failing before but they new ones are only detected because i made the test more accurate.
The previous version of the test accepted any exception when it was expecting a cancellation exception. It was passing on netfx with my previous changes because timeout exceptions were being thrown. I judged that accepting a timeout when we were supposed to be testing whether cancellation had occurred was not correct. If we retained the previous version of the test then everything would have passed cleanly. In the current situation since the test completed correctly without hanging the result is equivalent to what we would have experienced in all test runs in the past, all started threads that we expected to be cancelled exited with an exception. [edit] |
@Wraith2 You might be banging your head against an unrelated issue in the driver. IIRC, the test was only introduced to ensure we don't regress "The MARS TDS header contained errors." issue. (The test code came from the repro.) If you isolate your test changes and run them against main code, does it still fail? Yes, the correct exception is probably "Operation cancelled by user." where the exception is being caught. But if it's unrelated to your other changes, I would leave that part of the test as it was and file a new issue with repro code. As it is, it's unclear if and how this behavior is impacting users and I wouldn't hold up your perf improvements for it. |
There was definitely a real problem. The results differed between main and my branch. I've solved that issue now and the current state is that we're seeing a real failure because I've made the test more sensitive. I think it's probably safe to lower the sensitivity of the test again now because the new test that I've added covers the specific scenario in the multiplexer that I had missed and everything else is pass. I'll try that and see how the CI likes it. I think the current state on this branch is that it is as stable as live. We need to have confidence that this set of changes is correct before we can merge it. It's high risk and high complexity code. Even understanding it very deeply it has taken me a week to actively debug a very important behaviour change that I missed. |
Can someone re-run the failed legs? the only failing test is something to do with event counters which I've been no-where near. |
The failing test is EventCounter_ReclaimedConnectionsCounter_Functional. It's doing something with GC specific to net6. It's failing sporadically on net6 managed sni runs but not deterministically. I can't make it fail locally to trace what might be happening. |
Any thoughts? |
I'm not seeing the failures you mentioned in EventCounter_ReclaimedConnectionsCounter_Functional [in the CI results]. I mainly see fairly consistent failures of CancelAsyncConnections on Linux. It seems to pass on Windows managed SNI, so there might be something that is Linux/Ubuntu network specific. Can you run/debug the test against a local WSL or Docker instance? |
If i click through the failure i get to this page https://sqlclientdrivers.visualstudio.com/public/_build/results?buildId=95784&view=ms.vss-test-web.build-test-results-tab The cancel tests are passing now, those failed in the previous runs but not the current ones. |
If it's AsyncCancelledConnectionsTest again then there isn't anything further I can do. That test is multithreaded and timing dependent. I've traced the individual packets through the entire call stack. I've run it for 1000 iterations successfully after fixing a reproducible error in it. If someone can isolate a reproducible problem from it then i'll investigate. |
I chatted with @saurabh500 and I just want to add that this is definitely something we all want to see get merged. It'll just take someone finding time (could take a few days dedicated time) to get their head wrapped around the new code and be able to help repro/debug to find the issue. |
I'm happy to make myself available to talk through the code with anyone that needs it. |
@Wraith2 and @David-Engel I was looking at the lifecycle of the snapshots and something that stood out in NetCore vs NetFx is that SqlDataReader for NetCore is storing the cached snapshot with the SqlInternalConnectionTds which is a shared resource among all the SqlDataReader(s) running on a MARS connection.
This means that we are saving the reader snapshot on the shared resource, which can be overwritten by any other reader. @Wraith2 have you had a chance to pursue this line of investigation for hanging test? I wonder if the timing is causing the wrong cached snapshot to be provided to a SqlDataReader, causing data corruption and likely causing a hang. |
SqlInternalConnection.cs
|
@Wraith2 I see that you had made the changes in the first place. Can you try another PR where you remove the storage of these contexts and snapshots on SqlInternalConnection and with the multiplexing change, try to see if this solves the problem. Also, I am Happy to be told that my theory is wrong, but I would like to understand how in MARS cases, the shared Cached contexts on InternalConnection is a safe design choice. |
In each case where something goes wrong we need to know how we got there. In those dumps you can see that a large part of the packet data is filled with FF, that indicates that the particular buffer Is likely part of a multiple packets that got stuck together then the multiplexer pulled them apart filling the unused space with f's to help debugging. The problem is that knowing how we got to any particular place is complicated and the more test code you add the more you disrupt timings which change the observed behaviour. Ideally we'd be able to dump all packets at on the connection we're interested in as they leave the network layer for the tds layer but when we're running 100 connections this is both disruptive and very hard to implement. Each thread is using 350+ packets in just this short test. Given a sequence of 8K buffers we can, in theory, just run them through the test harness and see if the multiplexer deconstructs and reconstructs them successfully. Unfortunately there is another class of problem which the test harness can't cover, errors caused by internal behaviour of the real library in consuming packets. The test harness runs packets. The real library uses the data inside the packets to run. The data from your example:
looks like 2 packets. The
is one complete packet, and the buffer also contains another packet header
after this it's all the F's which shows that we've got the right bits of data because all the non-right bits were blanked. So the data is correctly accounted for but the current packet buffer should have been split out into two packets. The data inside the packet we're currently reading is the thing that triggered the IsValidTdsToken failure but it doesn't look like the failure is caused by packet reconstruction logic because the packets contents and lengths add up correctly. How do we fix it? I need a reproduction I can run quickly to the point of failure multiple times so I can add in debugging statements and breakpoints to poke at it. |
In this specific case I'd add something to console print, wait for attached debugger, break, whatever works and try to identify how a partial packet from |
@@ -3533,7 +3533,7 @@ private TdsOperationStatus TryNextResult(out bool more) | |||
if (result != TdsOperationStatus.Done) | |||
{ | |||
more = false; | |||
return TdsOperationStatus.Done; | |||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be fixed in main with a separete PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This originally came from my Wraith2#5 PR. I didn't spot it on the original OperationStatus PR, so decided to submit it for rollup into this one. I'm happy to push it into main directly too though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it has any implications if left in main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing in the current codebase needs to be able to tell the difference between Done and NeedMoreData. That will come in part3 of this series of PRs. So this can be here, or in main as a separate PR, doesn't really matter. It just seemed easiest to incorporate it into this change when @edwardneal pr'ed it into my repo.
Add debugging and tighten the exception detection in async cancel tests.
…en multiple can be present in a single partial buffer.
00c2426
to
29ad90b
Compare
I've rebased to main to fix the conflicts. Locally the net6 tests won't build but I'm hoping the CI has no problems with them. I've also added a try-catch around pending read increment/decrement which @MichelZ has found causing him problems during testing, other places in the code use a try catch pattern with this variable so it feels natural to add it in the location I have. I ran tests on windows with native SNI over the weekend and didn't enounter any test failures that trace back to partial packets. I had a small number of test failures where the cancellation had not been sent by the time the test completed (_attentionSending and _attentionSent were false). Those are a timing issue not to do with the change I've made. @cheenamalhotra and @saurabh500 can you review please? Given the timescales for the 6.0 release being fixed and it being an important LTS milestone I no longer think that this change should be part of that release. I think that the 6.0 should go out without this change ( and the required following change to enable fast async string) and that the versions after that should include these changes. Opinions? |
I ran this quite a few times now on multiple machines (Win, 16 cores/32 threads, Managed SNI, NET8 / Linux, 2 cores, NET8), and while I get some |
I've run this a few more times on my systems and the results look good to me. I'm tempted to say put it in 6.0 because I really want the async perf improvement in there, but that's probably not wise. 😄 |
It depends on the time remaining. The next PR is substantially easier and smaller. I thought release date was going to coincide with netconf but that's gone already. |
According to the 6.0.0 Milestone it's currently planned for Dec 9th |
Split out from #2608 per discussion detailed in #2608 (comment)
Adds packet multiplexer and covering tests.