Bug 237579 - [Curl] Implement WebSocketTask
Summary: [Curl] Implement WebSocketTask
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Don Olmstead
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-07 20:37 PST by Don Olmstead
Modified: 2022-05-29 18:11 PDT (History)
10 users (show)

See Also:


Attachments
WIP Patch (25.98 KB, patch)
2022-03-07 20:40 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
WIP Patch (26.65 KB, patch)
2022-03-07 20:49 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
WIP Patch (25.67 KB, patch)
2022-03-09 14:07 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
Patch (31.10 KB, patch)
2022-03-10 12:10 PST, Don Olmstead
achristensen: review-
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Don Olmstead 2022-03-07 20:37:56 PST
...
Comment 1 Don Olmstead 2022-03-07 20:40:20 PST Comment hidden (obsolete)
Comment 2 Alex Christensen 2022-03-07 20:43:57 PST
The entry point is in ThreadableWebSocketChannel::create
Comment 3 Don Olmstead 2022-03-07 20:49:04 PST Comment hidden (obsolete)
Comment 4 Don Olmstead 2022-03-09 14:07:48 PST Comment hidden (obsolete)
Comment 5 Don Olmstead 2022-03-10 12:10:35 PST
Created attachment 454391 [details]
Patch
Comment 6 Alex Christensen 2022-03-10 13:35:50 PST
Comment on attachment 454391 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=454391&action=review

Looks mostly good.  Thanks for upstreaming.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:46
> +    if (request.url().protocolIs("wss") && WebCore::DeprecatedGlobalSettings::allowsAnySSLCertificate())
> +        WebCore::CurlContext::singleton().sslHandle().setIgnoreSSLErrors(true);

It would be great if we could do this per task or at least per domain.  That's for a different patch, though.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:55
> +WebSocketTask::~WebSocketTask()
> +{
> +    destructStream();
> +}

This might be a sign that the stream should be a smart-pointer-like object that cleans up when destroyed.  It also might not.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:96
> +void WebSocketTask::cancel()
> +{
> +
> +}
> +
> +void WebSocketTask::resume()
> +{
> +
> +}

Do these need to do anything?

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:119
> +            handshakeMessage.remove(handshakeMessage.length() - 2, 2); // Remove the terminating '\r\n'
> +            handshakeMessage.append("Cookie: ");
> +            handshakeMessage.append(cookieHeaderField);
> +            handshakeMessage.append("\r\n\r\n");

This does 4 unnecessary string allocations and copies.  If handshakeMessage were a StringBuilder or even a Vector<char> it would be more efficient.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:125
> +    auto buffer = makeUniqueArray<uint8_t>(handshakeData.length());
> +    memcpy(buffer.get(), handshakeData.data(), handshakeData.length());

This is another copy and allocation that might be able to be removed.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:156
> +    auto frameResult = receiveFrames([this](WebCore::WebSocketFrame::OpCode opCode, const uint8_t* data, size_t length) {

It would probably be worth capturing a WeakPtr<WebSocketTask> and returning early if it's null to be safe against using this after it has been freed.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.cpp:422
> +    callOnMainRunLoop([this, code, reason] {

Ditto, this may be deallocated by the time the lambda executes, which would be bad.

> Source/WebKit/NetworkProcess/curl/WebSocketTaskCurl.h:64
> +    enum class State {

nit
 : uint8_t
Comment 7 Radar WebKit Bug Importer 2022-03-14 21:38:16 PDT
<rdar://problem/90287981>
Comment 8 Don Olmstead 2022-05-26 14:15:56 PDT
Pull request: https://github.com/webkit/webkit/pull/1071
Comment 9 EWS 2022-05-26 23:24:31 PDT
Committed r294932 (251043@main): <https://commits.webkit.org/251043@main>

Reviewed commits have been landed. Closing PR #1071 and removing active labels.
Comment 10 Fujii Hironori 2022-05-29 18:11:58 PDT
> Committed r294932 (251043@main): <https://commits.webkit.org/251043@main>

WinCairo WK1 is crashing.
Bug 241087 – [curl] REGRESSION(251043@main): "ASSERTION FAILED: channel" in WebCore::ThreadableWebSocketChannel::create