fix(net): fail fast on a dead Electrum connection instead of hanging

After a protocol error (e.g. a malformed line) the read loop ended but
the client still reported IsConnected and later requests waited forever
for a response that could never arrive. The read loop now marks the
connection closed before failing pending requests, and RequestAsync
throws IOException on a closed connection. Adds regression tests and a
raw-line helper to the fake server.
This commit is contained in:
davide committed 2026-11-03 11:45:43 +01:00
1 parent 9c0a408c49
commit cb93927d15
3 files changed
+54

No files matched your search

@@ -71,6 +71,14 @@ public sealed class FakeElectrumServer : IAsyncDisposable
await WriteLineAsync(stream, writeLock, line);
}
/// <summary>Sends an arbitrary (possibly malformed) line to every connected client.</summary>
public async Task SendRawAsync(string line)
{
var bytes = System.Text.Encoding.UTF8.GetBytes(line);
foreach (var (stream, writeLock, _) in _clients)
await WriteLineAsync(stream, writeLock, bytes);
}
/// <summary>Abruptly closes every accepted connection (tests the client's failure paths).</summary>
public void DropClients()
{