diff --git a/OpenDreamRuntime/DreamManager.Connections.cs b/OpenDreamRuntime/DreamManager.Connections.cs index 317659734c..5cba48bf6e 100644 --- a/OpenDreamRuntime/DreamManager.Connections.cs +++ b/OpenDreamRuntime/DreamManager.Connections.cs @@ -106,11 +106,18 @@ private async Task ConsumeAndHandleWorldTopicSocket(Socket remote, CancellationT var length = BitConverter.ToUInt16(buffer); buffer = new byte[length]; - var read = await from.ReceiveAsync(buffer, cancellationToken); - if (read != buffer.Length) { - _sawmill.Warning("failed to parse byond topic due to insufficient data read"); - return null; - } + var totalRead = 0; + do { + var read = await from.ReceiveAsync( + new Memory(buffer, totalRead, length - totalRead), + cancellationToken); + if(read == 0 && totalRead != length) { + _sawmill.Warning("failed to parse byond topic due to insufficient data read"); + return null; + } + + totalRead += read; + } while (totalRead < length); return Encoding.ASCII.GetString(buffer[6..^1]); } @@ -178,7 +185,7 @@ private async Task ConsumeAndHandleWorldTopicSocket(Socket remote, CancellationT await remote.DisconnectAsync(false, cancellationToken); } } catch (Exception ex) { - _sawmill.Warning("Error processing topic: {0}", ex); + _sawmill.Warning("Error processing topic #{0}: {1}", topicId, ex); } finally { _sawmill.Debug("Finished world topic #{0}", topicId); }