feat(boot): add server boot integration tests and fix ValueTask sync blocking

Fix Shutdown()/LameDuckMode() deadlock caused by calling .GetAwaiter().GetResult()
on pending ValueTask from Channel.ReadAsync(). ValueTask does not support synchronous
blocking — must convert via .AsTask() first. Add two integration tests validating the
full Start() → AcceptLoop → client connection → Shutdown lifecycle.
This commit is contained in:
Joseph Doherty
2026-03-01 15:13:48 -05:00
parent bd40b36c23
commit be1eb3392e
3 changed files with 120 additions and 3 deletions
@@ -127,8 +127,9 @@ public sealed partial class NatsServer
}
// Wait for accept loops to exit.
// Must use .AsTask() because ValueTask cannot be synchronously blocked on.
for (int i = 0; i < doneExpected; i++)
_done.Reader.ReadAsync().GetAwaiter().GetResult();
_done.Reader.ReadAsync().AsTask().GetAwaiter().GetResult();
// Wait for all goroutines.
_grWg.Wait();
@@ -655,8 +656,9 @@ public sealed partial class NatsServer
ShutdownRaftNodes();
// Wait for accept loops.
// Must use .AsTask() because ValueTask cannot be synchronously blocked on.
for (int i = 0; i < expected; i++)
_ldmCh.Reader.ReadAsync().GetAwaiter().GetResult();
_ldmCh.Reader.ReadAsync().AsTask().GetAwaiter().GetResult();
_mu.EnterWriteLock();
var clients = new List<ClientConnection>(_clients.Values);