Skip to content

Commit 72367aa

Browse files
CarnaViireManickaP
authored andcommitted
Change asserts
1 parent 24334ae commit 72367aa

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ private static bool IsTls13Disabled(bool isServer)
177177

178178
public void SetContext(MsQuicSafeHandle handle, void* context)
179179
{
180-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
181180
bool success = false;
182181
try
183182
{
184183
handle.DangerousAddRef(ref success);
185-
Debug.Assert(success);
184+
Debug.Assert(success || handle.IsInvalid);
185+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
186186
ApiTable->SetContext(handle.QuicHandle, context);
187187
}
188188
finally
@@ -196,12 +196,12 @@ public void SetContext(MsQuicSafeHandle handle, void* context)
196196

197197
public void* GetContext(MsQuicSafeHandle handle)
198198
{
199-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
200199
bool success = false;
201200
try
202201
{
203202
handle.DangerousAddRef(ref success);
204-
Debug.Assert(success);
203+
Debug.Assert(success || handle.IsInvalid);
204+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
205205
return ApiTable->GetContext(handle.QuicHandle);
206206
}
207207
finally
@@ -215,12 +215,12 @@ public void SetContext(MsQuicSafeHandle handle, void* context)
215215

216216
public void SetCallbackHandler(MsQuicSafeHandle handle, void* callback, void* context)
217217
{
218-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
219218
bool success = false;
220219
try
221220
{
222221
handle.DangerousAddRef(ref success);
223-
Debug.Assert(success);
222+
Debug.Assert(success || handle.IsInvalid);
223+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
224224
ApiTable->SetCallbackHandler(handle.QuicHandle, callback, context);
225225
}
226226
finally
@@ -234,12 +234,12 @@ public void SetCallbackHandler(MsQuicSafeHandle handle, void* callback, void* co
234234

235235
public int SetParam(MsQuicSafeHandle handle, uint param, uint bufferLength, void* buffer)
236236
{
237-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
238237
bool success = false;
239238
try
240239
{
241240
handle.DangerousAddRef(ref success);
242-
Debug.Assert(success);
241+
Debug.Assert(success || handle.IsInvalid);
242+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
243243
return ApiTable->SetParam(handle.QuicHandle, param, bufferLength, buffer);
244244
}
245245
finally
@@ -253,12 +253,12 @@ public int SetParam(MsQuicSafeHandle handle, uint param, uint bufferLength, void
253253

254254
public int GetParam(MsQuicSafeHandle handle, uint param, uint* bufferLength, void* buffer)
255255
{
256-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
257256
bool success = false;
258257
try
259258
{
260259
handle.DangerousAddRef(ref success);
261-
Debug.Assert(success);
260+
Debug.Assert(success || handle.IsInvalid);
261+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
262262
return ApiTable->GetParam(handle.QuicHandle, param, bufferLength, buffer);
263263
}
264264
finally
@@ -272,12 +272,12 @@ public int GetParam(MsQuicSafeHandle handle, uint param, uint* bufferLength, voi
272272

273273
public void RegistrationShutdown(MsQuicSafeHandle handle, QUIC_CONNECTION_SHUTDOWN_FLAGS flags, ulong code)
274274
{
275-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
276275
bool success = false;
277276
try
278277
{
279278
handle.DangerousAddRef(ref success);
280-
Debug.Assert(success);
279+
Debug.Assert(success || handle.IsInvalid);
280+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
281281
ApiTable->RegistrationShutdown(handle.QuicHandle, flags, code);
282282
}
283283
finally
@@ -291,12 +291,12 @@ public void RegistrationShutdown(MsQuicSafeHandle handle, QUIC_CONNECTION_SHUTDO
291291

292292
public int ConfigurationOpen(MsQuicSafeHandle regHandle, QUIC_BUFFER* alpnBuffers, uint alpnBuffersCount, QUIC_SETTINGS* settings, uint settingsSize, void* context, QUIC_HANDLE** configuration)
293293
{
294-
ObjectDisposedException.ThrowIf(regHandle.IsInvalid, regHandle);
295294
bool success = false;
296295
try
297296
{
298297
regHandle.DangerousAddRef(ref success);
299-
Debug.Assert(success);
298+
Debug.Assert(success || regHandle.IsInvalid);
299+
ObjectDisposedException.ThrowIf(regHandle.IsInvalid, regHandle);
300300
return ApiTable->ConfigurationOpen(regHandle.QuicHandle, alpnBuffers, alpnBuffersCount, settings, settingsSize, context, configuration);
301301
}
302302
finally
@@ -310,12 +310,12 @@ public int ConfigurationOpen(MsQuicSafeHandle regHandle, QUIC_BUFFER* alpnBuffer
310310

311311
public int ConfigurationLoadCredential(MsQuicSafeHandle handle, QUIC_CREDENTIAL_CONFIG* config)
312312
{
313-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
314313
bool success = false;
315314
try
316315
{
317316
handle.DangerousAddRef(ref success);
318-
Debug.Assert(success);
317+
Debug.Assert(success || handle.IsInvalid);
318+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
319319
return ApiTable->ConfigurationLoadCredential(handle.QuicHandle, config);
320320
}
321321
finally
@@ -329,12 +329,12 @@ public int ConfigurationLoadCredential(MsQuicSafeHandle handle, QUIC_CREDENTIAL_
329329

330330
public int ListenerOpen(MsQuicSafeHandle handle, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_LISTENER_EVENT*, int> callback, void* context, QUIC_HANDLE** listener)
331331
{
332-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
333332
bool success = false;
334333
try
335334
{
336335
handle.DangerousAddRef(ref success);
337-
Debug.Assert(success);
336+
Debug.Assert(success || handle.IsInvalid);
337+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
338338
return ApiTable->ListenerOpen(handle.QuicHandle, callback, context, listener);
339339
}
340340
finally
@@ -348,12 +348,12 @@ public int ListenerOpen(MsQuicSafeHandle handle, delegate* unmanaged[Cdecl]<QUIC
348348

349349
public int ListenerStart(MsQuicSafeHandle handle, QUIC_BUFFER* alpnBuffers, uint alpnBuffersCount, QuicAddr* localAddress)
350350
{
351-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
352351
bool success = false;
353352
try
354353
{
355354
handle.DangerousAddRef(ref success);
356-
Debug.Assert(success);
355+
Debug.Assert(success || handle.IsInvalid);
356+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
357357
return ApiTable->ListenerStart(handle.QuicHandle, alpnBuffers, alpnBuffersCount, localAddress);
358358
}
359359
finally
@@ -367,12 +367,12 @@ public int ListenerStart(MsQuicSafeHandle handle, QUIC_BUFFER* alpnBuffers, uint
367367

368368
public void ListenerStop(MsQuicSafeHandle handle)
369369
{
370-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
371370
bool success = false;
372371
try
373372
{
374373
handle.DangerousAddRef(ref success);
375-
Debug.Assert(success);
374+
Debug.Assert(success || handle.IsInvalid);
375+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
376376
ApiTable->ListenerStop(handle.QuicHandle);
377377
}
378378
finally
@@ -386,12 +386,12 @@ public void ListenerStop(MsQuicSafeHandle handle)
386386

387387
public int ConnectionOpen(MsQuicSafeHandle regHandle, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_CONNECTION_EVENT*, int> callback, void* context, QUIC_HANDLE** connection)
388388
{
389-
ObjectDisposedException.ThrowIf(regHandle.IsInvalid, regHandle);
390389
bool success = false;
391390
try
392391
{
393392
regHandle.DangerousAddRef(ref success);
394-
Debug.Assert(success);
393+
Debug.Assert(success || regHandle.IsInvalid);
394+
ObjectDisposedException.ThrowIf(regHandle.IsInvalid, regHandle);
395395
return ApiTable->ConnectionOpen(regHandle.QuicHandle, callback, context, connection);
396396
}
397397
finally
@@ -405,12 +405,12 @@ public int ConnectionOpen(MsQuicSafeHandle regHandle, delegate* unmanaged[Cdecl]
405405

406406
public void ConnectionShutdown(MsQuicSafeHandle handle, QUIC_CONNECTION_SHUTDOWN_FLAGS flags, ulong code)
407407
{
408-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
409408
bool success = false;
410409
try
411410
{
412411
handle.DangerousAddRef(ref success);
413-
Debug.Assert(success);
412+
Debug.Assert(success || handle.IsInvalid);
413+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
414414
ApiTable->ConnectionShutdown(handle.QuicHandle, flags, code);
415415
}
416416
finally
@@ -424,16 +424,17 @@ public void ConnectionShutdown(MsQuicSafeHandle handle, QUIC_CONNECTION_SHUTDOWN
424424

425425
public int ConnectionStart(MsQuicSafeHandle handle, MsQuicSafeHandle configHandle, ushort family, sbyte* serverName, ushort serverPort)
426426
{
427-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
428-
ObjectDisposedException.ThrowIf(configHandle.IsInvalid, configHandle);
429427
bool success = false;
430428
bool configSuccess = false;
431429
try
432430
{
433431
handle.DangerousAddRef(ref success);
434-
Debug.Assert(success);
432+
Debug.Assert(success || handle.IsInvalid);
433+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
435434
configHandle.DangerousAddRef(ref configSuccess);
436-
Debug.Assert(configSuccess);
435+
Debug.Assert(configSuccess || configHandle.IsInvalid);
436+
ObjectDisposedException.ThrowIf(configHandle.IsInvalid, configHandle);
437+
437438
return ApiTable->ConnectionStart(handle.QuicHandle, configHandle.QuicHandle, family, serverName, serverPort);
438439
}
439440
finally
@@ -451,16 +452,17 @@ public int ConnectionStart(MsQuicSafeHandle handle, MsQuicSafeHandle configHandl
451452

452453
public int ConnectionSetConfiguration(MsQuicSafeHandle handle, MsQuicSafeHandle configHandle)
453454
{
454-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
455-
ObjectDisposedException.ThrowIf(configHandle.IsInvalid, configHandle);
456455
bool success = false;
457456
bool configSuccess = false;
458457
try
459458
{
460459
handle.DangerousAddRef(ref success);
461-
Debug.Assert(success);
460+
Debug.Assert(success || handle.IsInvalid);
461+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
462462
configHandle.DangerousAddRef(ref configSuccess);
463-
Debug.Assert(configSuccess);
463+
Debug.Assert(configSuccess || configHandle.IsInvalid);
464+
ObjectDisposedException.ThrowIf(configHandle.IsInvalid, configHandle);
465+
464466
return ApiTable->ConnectionSetConfiguration(handle.QuicHandle, configHandle.QuicHandle);
465467
}
466468
finally
@@ -478,12 +480,12 @@ public int ConnectionSetConfiguration(MsQuicSafeHandle handle, MsQuicSafeHandle
478480

479481
public int StreamOpen(MsQuicSafeHandle connHandle, QUIC_STREAM_OPEN_FLAGS flags, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_STREAM_EVENT*, int> callback, void* context, QUIC_HANDLE** stream)
480482
{
481-
ObjectDisposedException.ThrowIf(connHandle.IsInvalid, connHandle);
482483
bool success = false;
483484
try
484485
{
485486
connHandle.DangerousAddRef(ref success);
486-
Debug.Assert(success);
487+
Debug.Assert(success || connHandle.IsInvalid);
488+
ObjectDisposedException.ThrowIf(connHandle.IsInvalid, connHandle);
487489
return ApiTable->StreamOpen(connHandle.QuicHandle, flags, callback, context, stream);
488490
}
489491
finally
@@ -497,12 +499,12 @@ public int StreamOpen(MsQuicSafeHandle connHandle, QUIC_STREAM_OPEN_FLAGS flags,
497499

498500
public int StreamStart(MsQuicSafeHandle handle, QUIC_STREAM_START_FLAGS flags)
499501
{
500-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
501502
bool success = false;
502503
try
503504
{
504505
handle.DangerousAddRef(ref success);
505-
Debug.Assert(success);
506+
Debug.Assert(success || handle.IsInvalid);
507+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
506508
return ApiTable->StreamStart(handle.QuicHandle, flags);
507509
}
508510
finally
@@ -516,12 +518,12 @@ public int StreamStart(MsQuicSafeHandle handle, QUIC_STREAM_START_FLAGS flags)
516518

517519
public int StreamShutdown(MsQuicSafeHandle handle, QUIC_STREAM_SHUTDOWN_FLAGS flags, ulong code)
518520
{
519-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
520521
bool success = false;
521522
try
522523
{
523524
handle.DangerousAddRef(ref success);
524-
Debug.Assert(success);
525+
Debug.Assert(success || handle.IsInvalid);
526+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
525527
return ApiTable->StreamShutdown(handle.QuicHandle, flags, code);
526528
}
527529
finally
@@ -535,12 +537,12 @@ public int StreamShutdown(MsQuicSafeHandle handle, QUIC_STREAM_SHUTDOWN_FLAGS fl
535537

536538
public int StreamSend(MsQuicSafeHandle handle, QUIC_BUFFER* buffers, uint buffersCount, QUIC_SEND_FLAGS flags, void* context)
537539
{
538-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
539540
bool success = false;
540541
try
541542
{
542543
handle.DangerousAddRef(ref success);
543-
Debug.Assert(success);
544+
Debug.Assert(success || handle.IsInvalid);
545+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
544546
return ApiTable->StreamSend(handle.QuicHandle, buffers, buffersCount, flags, context);
545547
}
546548
finally
@@ -554,12 +556,12 @@ public int StreamSend(MsQuicSafeHandle handle, QUIC_BUFFER* buffers, uint buffer
554556

555557
public void StreamReceiveComplete(MsQuicSafeHandle handle, ulong length)
556558
{
557-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
558559
bool success = false;
559560
try
560561
{
561562
handle.DangerousAddRef(ref success);
562-
Debug.Assert(success);
563+
Debug.Assert(success || handle.IsInvalid);
564+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
563565
ApiTable->StreamReceiveComplete(handle.QuicHandle, length);
564566
}
565567
finally
@@ -573,12 +575,12 @@ public void StreamReceiveComplete(MsQuicSafeHandle handle, ulong length)
573575

574576
public int StreamReceiveSetEnabled(MsQuicSafeHandle handle, byte enabled)
575577
{
576-
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
577578
bool success = false;
578579
try
579580
{
580581
handle.DangerousAddRef(ref success);
581-
Debug.Assert(success);
582+
Debug.Assert(success || handle.IsInvalid);
583+
ObjectDisposedException.ThrowIf(handle.IsInvalid, handle);
582584
return ApiTable->StreamReceiveSetEnabled(handle.QuicHandle, enabled);
583585
}
584586
finally

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ private unsafe int HandleEventSendComplete(ref SEND_COMPLETE data)
526526
NetEventSource.Info(this, $"{this} Received event SEND_COMPLETE with {nameof(data.Canceled)}={data.Canceled}");
527527
}
528528

529-
// In case of cancellation, the task from _sendTcs is finished before the aborting. It is technically possible for subsequent WriteAsync to grab the next task
529+
// In case of cancellation, the task from _sendTcs is finished before the aborting. It is technically possible for subsequent WriteAsync to grab the next task
530530
// from _sendTcs and start executing before SendComplete event occurs for the previous (canceled) write
531531
lock (_sendBuffersLock)
532532
{

0 commit comments

Comments
 (0)