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

Use an IBufferWriter<byte> to write the outgoing SSPI blob #2452

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

twsouthwick
Copy link
Member

@twsouthwick twsouthwick commented Apr 8, 2024

This change removes the need to pre-allocate anything for the outgoing blobs of SSPI generation. As part of this:

  • An internal implementation of ArrayBufferWriter is added for platforms that do not support it
  • SqlObjectPool is imbued with the ability to create/reset pooled objects
  • TdsParser/TdsLogin is updated to use pooled ArrayBufferWriter instances to generate SSPI blobs
  • Native methods are updated to take in Span/* for writeable byte[]
  • SSPIContextProvider signature is updated to take IBufferWriter

Part of #2253

This change removes the need to pre-allocate anything for the outgoing blobs of SSPI generation. As part of this:

- An internal implementation of ArrayBufferWriter is added for platforms that do not support it
- SqlObjectPool is imbued with the ability to create/reset pooled objects
- TdsParser/TdsLogin is updated to use pooled ArrayBufferWriter instances to generate SSPI blobs
- Native methods are updated to take in Span/* for writeable byte[]
- SSPIContextProvider signature is updated to take IBufferWriter
@twsouthwick twsouthwick marked this pull request as ready for review May 7, 2024 21:20
@twsouthwick
Copy link
Member Author

@David-Engel can I get a review on this next step in the SSPI journey?

Copy link

codecov bot commented May 8, 2024

Codecov Report

Attention: Patch coverage is 75.89286% with 27 lines in your changes missing coverage. Please review.

Project coverage is 72.71%. Comparing base (f7ab115) to head (6bc8358).
Report is 17 commits behind head on main.

Current head 6bc8358 differs from pull request most recent head 7c3335e

Please upload reports for the commit 7c3335e to get more accurate results.

Files Patch % Lines
.../src/Microsoft/Data/SqlClient/ArrayBufferWriter.cs 56.25% 21 Missing ⚠️
...osoft/Data/SqlClient/TdsParserStateObject.netfx.cs 72.22% 5 Missing ⚠️
...t/Data/SqlClient/SSPI/NativeSSPIContextProvider.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2452      +/-   ##
==========================================
- Coverage   72.81%   72.71%   -0.11%     
==========================================
  Files         311      314       +3     
  Lines       61694    61787      +93     
==========================================
+ Hits        44922    44926       +4     
- Misses      16772    16861      +89     
Flag Coverage Δ
addons 92.88% <ø> (ø)
netcore 77.02% <94.59%> (-0.16%) ⬇️
netfx 70.42% <73.52%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@twsouthwick
Copy link
Member Author

@David-Engel ping

@David-Engel
Copy link
Contributor

I ran our internal Kerberos test pipeline against this PR and all tests passed.

@twsouthwick
Copy link
Member Author

@David-Engel David-Engel added this to the 6.0-preview1 milestone Jun 3, 2024
@twsouthwick
Copy link
Member Author

@David-Engel can you run this on the kerberos suite again?

@twsouthwick
Copy link
Member Author

@David-Engel something is up with the merges so let me get those fixed before you do the kerberos runs

@twsouthwick
Copy link
Member Author

@David-Engel I'm getting sporadic errors that don't seem to always repro: https://sqlclientdrivers.visualstudio.com/public/_build/results?buildId=96359&view=logs&j=b14281d2-3365-502e-c6c8-e9e46d660715&t=a67f9feb-8bad-50ac-92c7-d62292e3e6fb&l=63

Have you seen these or are they related to my pr?

@@ -519,6 +519,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlObjectPool.cs">
<Link>Microsoft\Data\SqlClient\SqlObjectPool.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ArrayBufferWriter.cs">
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor adjustment here to keep the files in alphabetically order.

<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlObjectPool.cs">
<Link>Microsoft\Data\SqlClient\SqlObjectPool.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ArrayBufferWriter.cs">
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note here.

// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if NETFRAMEWORK || NETSTANDARD
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no NetStandard anymore.

Suggested change
#if NETFRAMEWORK || NETSTANDARD
#if NETFRAMEWORK


private static void ThrowInvalidOperationException_AdvancedTooFar(int capacity)
{
throw new InvalidOperationException($"Buffer advanced to far: {capacity}");
Copy link
Contributor

Choose a reason for hiding this comment

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

The new message should be added in the Strings.res.


private static void ThrowOutOfMemoryException(uint capacity)
{
throw new OutOfMemoryException($"Buffer maximum size exceeded: {capacity}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note here.


if (rentedSSPIBuff != null)
if (sspiWriter is { })
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the is not null has more readability over this pattern in the cases like this.

@@ -8,6 +8,8 @@ namespace Microsoft.Data.SqlClient
{
internal partial class TdsParser
{
private static readonly SqlObjectPool<ArrayBufferWriter<byte>> _writers = new(20, () => new(), a => a.Clear());
Copy link
Contributor

Choose a reason for hiding this comment

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

No complain here only I'm curious about the constant 20 pooled objects here!
cc @David-Engel

@David-Engel
Copy link
Contributor

@David-Engel I'm getting sporadic errors that don't seem to always repro: https://sqlclientdrivers.visualstudio.com/public/_build/results?buildId=96359&view=logs&j=b14281d2-3365-502e-c6c8-e9e46d660715&t=a67f9feb-8bad-50ac-92c7-d62292e3e6fb&l=63

Have you seen these or are they related to my pr?

I think they are. CI runs against main are clean. The failures point to integrated authentication when running against a named instance.

@cheenamalhotra cheenamalhotra removed this from the 6.0-preview2 milestone Oct 5, 2024
@cheenamalhotra
Copy link
Member

@twsouthwick

Getting back to prioritizing these PRs, can you please address pending feedback and update branch? Thanks!

@twsouthwick
Copy link
Member Author

Sure! It'll be about a week until I can look at it, but I'll get to it

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.

4 participants