LibIPC: Retry post_message write on EAGAIN and yield

This is a quick and dirty fix to at least get the Inspector working
again. This is a very bad solution long term, because it will spin on
the EventLoop. That is why there is a message reminding everyone this
problem still needs to be fixed, every time this is actually done.
This commit is contained in:
FrHun 2022-07-03 18:29:06 +02:00 committed by Andreas Kling
parent 720e0a096f
commit 96276c87cf
Notes: sideshowbarker 2024-07-17 08:54:26 +09:00

View File

@ -49,11 +49,20 @@ ErrorOr<void> ConnectionBase::post_message(MessageBuffer buffer)
#endif
ReadonlyBytes bytes_to_write { buffer.data.span() };
int writes_done = 0;
size_t initial_size = bytes_to_write.size();
while (!bytes_to_write.is_empty()) {
auto maybe_nwritten = m_socket->write(bytes_to_write);
writes_done++;
if (maybe_nwritten.is_error()) {
auto error = maybe_nwritten.release_error();
if (error.is_errno()) {
// FIXME: This is a hacky way to at least not crash on large messages
// The limit of 100 writes is arbitrary, and there to prevent indefinite spinning on the EventLoop
if (error.code() == EAGAIN && writes_done < 100) {
sched_yield();
continue;
}
shutdown_with_error(error);
switch (error.code()) {
case EPIPE:
@ -70,6 +79,9 @@ ErrorOr<void> ConnectionBase::post_message(MessageBuffer buffer)
bytes_to_write = bytes_to_write.slice(maybe_nwritten.value());
}
if (writes_done > 1) {
dbgln("LibIPC::Connection FIXME Warning, needed {} writes needed to send message of size {}B, this is pretty bad, as it spins on the EventLoop", writes_done, initial_size);
}
m_responsiveness_timer->start();
return {};