Skip to content

Commit c18ebea

Browse files
committed
Relieve unwanted pressure on the web socket wrapper queue that caused huge memory spikes (this loop would be very fast and cause tons of actions to be scheduled when there should be none). Issue #990
1 parent d8e7646 commit c18ebea

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Couchbase.Lite.Shared/Sync/WebSocketWrapper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,13 @@ private void PerformRead()
392392

393393
// Phew, at this point we are clear to actually read from the stream
394394
var received = stream.Read(_buffer, 0, _buffer.Length);
395+
if (received == 0) {
396+
// Should only happen on a closed stream, but just in case let's continue
397+
// after a small delay (wait for cancellation to confirm)
398+
Thread.Sleep(200);
399+
continue;
400+
}
401+
395402
var data = _buffer.Take(received).ToArray();
396403
Receive(data);
397404
} catch (Exception e) {

0 commit comments

Comments
 (0)