Test server: a dropped connection closes on every platform
On Linux, aborting the server-side WebSocket left the TCP connection open, so the client never saw the drop and the reconnect test timed out on the Gitea runner. Ending the response closes it everywhere, as a real server's drop does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
84155c0d18
commit
32878d825e
1 changed files with 7 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ internal sealed class TestSocketServer : IDisposable
|
||||||
private readonly CancellationTokenSource _cts = new();
|
private readonly CancellationTokenSource _cts = new();
|
||||||
private readonly Task _accept;
|
private readonly Task _accept;
|
||||||
private WebSocket? _current;
|
private WebSocket? _current;
|
||||||
|
private HttpListenerContext? _currentContext;
|
||||||
|
|
||||||
public TestSocketServer()
|
public TestSocketServer()
|
||||||
{
|
{
|
||||||
|
|
@ -53,7 +54,12 @@ internal sealed class TestSocketServer : IDisposable
|
||||||
{
|
{
|
||||||
WebSocket socket = await WaitForSocketAsync();
|
WebSocket socket = await WaitForSocketAsync();
|
||||||
socket.Abort();
|
socket.Abort();
|
||||||
|
// Aborting the socket alone leaves the TCP connection open on some
|
||||||
|
// platforms' listeners, so the client never sees the drop; ending the
|
||||||
|
// response closes the connection everywhere, as a real server's drop does.
|
||||||
|
_currentContext?.Response.Abort();
|
||||||
_current = null;
|
_current = null;
|
||||||
|
_currentContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string NextFrame(int timeoutMs = 5000)
|
public string NextFrame(int timeoutMs = 5000)
|
||||||
|
|
@ -111,6 +117,7 @@ internal sealed class TestSocketServer : IDisposable
|
||||||
Secrets.Enqueue(context.Request.Headers["X-Plugin-Secret"]);
|
Secrets.Enqueue(context.Request.Headers["X-Plugin-Secret"]);
|
||||||
HttpListenerWebSocketContext ws = await context.AcceptWebSocketAsync(null);
|
HttpListenerWebSocketContext ws = await context.AcceptWebSocketAsync(null);
|
||||||
_current = ws.WebSocket;
|
_current = ws.WebSocket;
|
||||||
|
_currentContext = context;
|
||||||
_ = Task.Run(() => ReadLoopAsync(ws.WebSocket));
|
_ = Task.Run(() => ReadLoopAsync(ws.WebSocket));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue