@@ -14,32 +14,39 @@ internal void ProcessSSPI(int receivedLength)
14
14
15
15
SniContext outerContext = _physicalStateObj . SniContext ;
16
16
_physicalStateObj . SniContext = SniContext . Snix_ProcessSspi ;
17
+
17
18
// allocate received buffer based on length from SSPI message
18
19
byte [ ] receivedBuff = ArrayPool < byte > . Shared . Rent ( receivedLength ) ;
19
20
20
- // read SSPI data received from server
21
- Debug . Assert ( _physicalStateObj . _syncOverAsync , "Should not attempt pends in a synchronous call" ) ;
22
- TdsOperationStatus result = _physicalStateObj . TryReadByteArray ( receivedBuff , receivedLength ) ;
23
- if ( result != TdsOperationStatus . Done )
21
+ try
24
22
{
25
- throw SQL . SynchronousCallMayNotPend ( ) ;
26
- }
23
+ // read SSPI data received from server
24
+ Debug . Assert ( _physicalStateObj . _syncOverAsync , "Should not attempt pends in a synchronous call" ) ;
25
+ TdsOperationStatus result = _physicalStateObj . TryReadByteArray ( receivedBuff , receivedLength ) ;
26
+ if ( result != TdsOperationStatus . Done )
27
+ {
28
+ throw SQL . SynchronousCallMayNotPend ( ) ;
29
+ }
27
30
28
- // allocate send buffer and initialize length
29
- var writer = SqlObjectPools . BufferWriter . Rent ( ) ;
31
+ // allocate send buffer and initialize length
32
+ var writer = SqlObjectPools . BufferWriter . Rent ( ) ;
30
33
31
- try
32
- {
33
- // make call for SSPI data
34
- _authenticationProvider ! . SSPIData ( receivedBuff . AsSpan ( 0 , receivedLength ) , writer , _serverSpn ) ;
34
+ try
35
+ {
36
+ // make call for SSPI data
37
+ _authenticationProvider ! . SSPIData ( receivedBuff . AsSpan ( 0 , receivedLength ) , writer , _serverSpn ) ;
35
38
36
- // DO NOT SEND LENGTH - TDS DOC INCORRECT! JUST SEND SSPI DATA!
37
- _physicalStateObj . WriteByteSpan ( writer . WrittenSpan ) ;
39
+ // DO NOT SEND LENGTH - TDS DOC INCORRECT! JUST SEND SSPI DATA!
40
+ _physicalStateObj . WriteByteSpan ( writer . WrittenSpan ) ;
38
41
42
+ }
43
+ finally
44
+ {
45
+ SqlObjectPools . BufferWriter . Return ( writer ) ;
46
+ }
39
47
}
40
48
finally
41
49
{
42
- SqlObjectPools . BufferWriter . Return ( writer ) ;
43
50
ArrayPool < byte > . Shared . Return ( receivedBuff , clearArray : true ) ;
44
51
}
45
52
0 commit comments