Skip to content

Commit

Permalink
Fix debug server hanging forever on a blocking peek() (#1698)
Browse files Browse the repository at this point in the history
Co-authored-by: amylizzle <amylizzle@users.noreply.github.com>
  • Loading branch information
amylizzle and amylizzle authored Mar 18, 2024
1 parent 6df7365 commit 2263e77
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions OpenDreamRuntime/Procs/DebugAdapter/DebugAdapterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public DebugAdapterClient(TcpClient client) {
public void HandleMessages() {
// `_netStream.DataAvailable` goes to false as soon as there is one Read call.
// `_client` and `_netReader` each keep buffers and we have to loop until they are all drained.
while (_client.Connected && (_netStream.DataAvailable || _client.Available > 0 || _netReader.Peek() != -1)) {
ProtocolMessage? message = ReadRequest();
if (message == null)
continue;

_sawmill.Log(LogLevel.Verbose, $"Parsed {message}");
_seqCounter = message.Seq + 1;
switch (message) {
case Request req:
OnRequest?.Invoke(this, req);
break;
}
}
try {
_netReader.BaseStream.ReadTimeout = 1; //1ms is lowest possible value
if(_client.Connected && (_netStream.DataAvailable || _client.Available > 0)) //check for buffered messages only once per tick
while (ReadRequest() is { } message) { //then process each message sequentially until there are none left
_sawmill.Log(LogLevel.Verbose, $"Parsed {message}");
_seqCounter = message.Seq + 1;
switch (message) {
case Request req:
OnRequest?.Invoke(this, req);
break;
}
}
} catch (IOException) {} //ignore timeouts
}

public void Close() {
Expand Down

0 comments on commit 2263e77

Please sign in to comment.