Skip to content

Commit d92f4aa

Browse files
committed
Set a large timeout when calling lws_service
Newer versions of libwebsockets ignore this value, but older ones interpret 0 to mean return immediately if there is nothing to do, which causes the thread to constantly loop consumming 100% of one CPU core. Bug: b/469864493
1 parent d7e13cf commit d92f4aa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

base/cvd/cuttlefish/host/frontend/webrtc/client_server.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ int ClientFilesServer::port() const {
101101

102102
void ClientFilesServer::Serve() {
103103
while (running_) {
104-
if (lws_service(context_, 0) < 0) {
104+
// Set a large timeout so it doesn't unnecessarily wake the thread too
105+
// frequently. Newer versions of libwebsockets ignore this value and only
106+
// return once some action was taken, but older ones respect it and there is
107+
// no way to tell them to wait indefinitely.
108+
int poll_timeout_ms = 1000000;
109+
if (lws_service(context_, poll_timeout_ms) < 0) {
105110
LOG(ERROR) << "Error serving client files";
106111
return;
107112
}

0 commit comments

Comments
 (0)