Commit 9bc27b1d authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

[mojo-core] Fix potential hang in ChannelPosix

It turns out that we were not putting the IO thread back to sleep when a
message header indicates that we should expect more bytes but those
bytes aren't available yet. In production this could lead to excess CPU
usage when receiving large messages, and it can also lead to IO-thread
hangs if a properly malformed message is sent to a receiving Channel.

This fixes the hang by properly breaking out of our read loop when
recvmsg returns EAGAIN or EWOULDBLOCK.

Bug: 909801
Change-Id: Icc10cbd9c2ddec7e33a68ab9b4d53b755b650cbb
Reviewed-on: https://chromium-review.googlesource.com/c/1361623Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#613786}
parent 66ed852e
......@@ -472,6 +472,11 @@ class ChannelPosix : public Channel,
(errno != EAGAIN && errno != EWOULDBLOCK)) {
read_error = true;
break;
} else {
// We expect more data but there is none to read. The
// FileDescriptorWatcher will wake us up again once there is.
DCHECK(errno == EAGAIN || errno == EWOULDBLOCK);
return;
}
} while (bytes_read == buffer_capacity &&
total_bytes_read < kMaxBatchReadCapacity && next_read_size > 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment