Describe the bug
The unit test ConnectionTests.TestInvalidDatabase is flaky and can fail on CI runs with a gRPC Unavailable status instead of the expected NotFound status.
Error details
units (9.0.x, ubuntu-latest) spanner-ado-net-tests 2026-06-24T11:52:28.2154838Z Failed TestInvalidDatabase [44 ms]
units (9.0.x, ubuntu-latest) spanner-ado-net-tests 2026-06-24T11:52:28.2155314Z Error Message:
units (9.0.x, ubuntu-latest) spanner-ado-net-tests 2026-06-24T11:52:28.2155982Z Assert.That(exception.Code, Is.EqualTo(Code.NotFound))
units (9.0.x, ubuntu-latest) spanner-ado-net-tests 2026-06-24T11:52:28.2156866Z Expected: NotFound
units (9.0.x, ubuntu-latest) spanner-ado-net-tests 2026-06-24T11:52:28.2157299Z But was: Unavailable
Stack trace
at Google.Cloud.Spanner.DataProvider.Tests.ConnectionTests.TestInvalidDatabase() in /home/runner/work/dotnet-spanner-entity-framework/dotnet-spanner-entity-framework/spanner-ado-net/spanner-ado-net-tests/ConnectionTests.cs:line 249
Investigation & Root Cause
The flake is caused by a race condition during the rapid teardown and restart of the Go proxy server process:
TestInvalidDatabase calls SpannerPool.CloseSpannerLib(), which asynchronously kills the running Go proxy server wrapper using process.Kill().
- This abruptly closes all active TCP connections to the in-memory C# mock server. The C# mock server needs a few milliseconds to clean up the closed channels.
- The test immediately opens a new connection, which spawns a new Go proxy server.
- The new proxy tries to connect to the C# mock server on
Fixture.Port immediately. Since the mock server is still cleaning up from the abrupt teardown, it rejects the new connection, throwing Unavailable.
Proposed Fix
Update Server.Stop() to wait for the process to exit synchronously after calling Kill(), ensuring socket and handle release is complete before execution proceeds:
public void Stop()
{
if (_process == null || _process.HasExited)
{
return;
}
_process.Kill();
_process.WaitForExit(1000); // Wait up to 1 second for termination
}
Describe the bug
The unit test
ConnectionTests.TestInvalidDatabaseis flaky and can fail on CI runs with a gRPCUnavailablestatus instead of the expectedNotFoundstatus.Error details
Stack trace
Investigation & Root Cause
The flake is caused by a race condition during the rapid teardown and restart of the Go proxy server process:
TestInvalidDatabasecallsSpannerPool.CloseSpannerLib(), which asynchronously kills the running Go proxy server wrapper usingprocess.Kill().Fixture.Portimmediately. Since the mock server is still cleaning up from the abrupt teardown, it rejects the new connection, throwingUnavailable.Proposed Fix
Update
Server.Stop()to wait for the process to exit synchronously after callingKill(), ensuring socket and handle release is complete before execution proceeds: