Created attachment 432351 [details] images and documents to reproduce I've build WebKit on windows and I'm playing around with the MiniBrowser. I've made a local html page with some javascript which uses a websocket to connect to a local server (seperate application, using boost). As soon as the websocket is opened, the cpu load goes skyhigh, cpu goes in full speed, 1 core full time busy. I've traced it to some libcurl functions, see attachments. I've like to help fixing it, but I do need some pointers given my very limited knowledge about webkit. attached is some information to reproduce the issue: - html document which includes javascript file - javascript file which opens websocket and does nothing - screenshot of task manager - screenshot of visual studio attached to WebKitNetworkProcess.exe Starting of the build: c:\[...]>perl tools\Scripts\build-webkit --wincairo --release Updating WebKitRequirementsWin64.zip... Found existing release: v2021.05.26 Seeking latest release from WebKitForWindows/WebKitRequirements... Found release to download: v2021.05.26 Already up-to-date!
FWIW, I cannot reproduce this with macOS Safari (needed to adjust the test to run, app2.js -> app3.js).
hmm, thats unfortunate, I've tried to debug it a little bit but as soon as I add this: ... } while (rc == -1 && errno == EINTR); std::cout << std::chrono::system_clock::now().time_since_epoch().count() / 1000 << " errno: " << errno << " rc: " << rc << std::endl; for (auto& stream : m_streamList.values()) ... in CurlStreamScheduler.cpp, the issue goes away (and nothing shows in any terminal unfortunately, though I added AllocConsole() earlier) It seems like ::select() is returning constantly, that could maybe explain the hot path as shown in the attachment earlier. I'm not sure how to continue.
rc = ::select(maxfd + 1, &readfds, &writefds, &exceptfds, &timeout); } while (rc == -1 && errno == EINTR); for (auto& stream : m_streamList.values()) I've increased the timeout value to 2000000 us, my webpage is loaded, websocket connection is made, no data is transfering (checked with wireshark) and I put a breakpoint at the line starting with 'for (...' the breakpoint triggers instantly and what I see is that readfds has a count of 1, writefds has a count of 0, exceptfds has a count of 1. they all contain the same data: [0] 1084 [1] 1475739.... rest is all equal to [1] (uninitialized I assume) continuing the function 'TryToTransfer' results in curl returning CURLE_AGAIN. I would not expect the readfds to return when no data is transfered, does exceptfds give a clue?
just wondering: at the bottom of appendMonitoringFd(): if (maxfd < *socket) maxfd = *socket; at the end the the call, maxfd is -1, and the 'maxfx = *socket' is not executed when I step through with the debugger. changing it to: int a = *socket; if (maxfd < a) maxfd = a; somehow resolved this :s
<rdar://problem/80150503>
Given this is windows/curl specific, maybe windows port maintainer could help you further investigating the issue.
Created attachment 432906 [details] test case Thank you very much for testing WinCairo and reporting the bug. I can reproduce the CPU 100% WebKitNetwork.exe problem. Will check. And, I found that WinCairo has the critical regression at the moment. Bug 227694 – [curl][Win] wss: WebSocket doesn't work since r271170
curl_socket_t is SOCKET on Windows. SOCKET is UINT_PTR in WinSock. https://github.com/WebKit/WebKit/blob/eab9b2b8ee9405ca95bb415f5ddf58766afe0159/Source/WebCore/platform/network/curl/CurlStream.cpp#L10 > if (maxfd < socket) This condition can't be true.
Created attachment 432908 [details] WIP patch
Created attachment 432910 [details] WIP patch
Created attachment 432911 [details] Patch
Comment on attachment 432911 [details] Patch Clearing flags on attachment: 432911 Committed r279576 (239407@main): <https://commits.webkit.org/239407@main>
All reviewed patches have been landed. Closing bug.