[webkit-changes] [WebKit/WebKit] ebe1ce: Close a WebSocketTask if it completes with an erro...

Alex Christensen noreply at github.com
Fri May 10 12:44:38 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: ebe1ce92f75fb6c7eac7fc2002af43df30723be7
      https://github.com/WebKit/WebKit/commit/ebe1ce92f75fb6c7eac7fc2002af43df30723be7
  Author: Alex Christensen <achristensen at apple.com>
  Date:   2024-05-10 (Fri, 10 May 2024)

  Changed paths:
    M Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

  Log Message:
  -----------
  Close a WebSocketTask if it completes with an error without closing properly
https://bugs.webkit.org/show_bug.cgi?id=274003
rdar://110487778

Reviewed by Brady Eidson.

If the TCP connection has an error but we have not received a close frame, then
CFNetwork will call didCompleteWithError but won't call the completion block of
receiveMessageWithCompletionHandler.  This is strange, but to make our interface
with CFNetwork more robust, close the WebSocket in this case if it hasn't already
been closed.  WebSocketTask::didClose will ignore this call if it has already
been closed.

Unfortunately, the API doesn't exist to make a unit test for this.  In attempting
to make a unit test, I filed rdar://127883777 which, when resolved will allow us
to test cases similar to this.  That radar shows that future work is still to be
done in this area, but manual testing verifies this fixes the issue in the
original radar of rdar://110487778

There are 3 ways a WebSocketTask can close:
1. receiveMessageWithCompletionHandler completion block can be called with an error
2. URLSession:webSocketTask:didCloseWithCode:reason: can be called
3. URLSession:task:didCompleteWithError: can be called
It is an error for didCompleteWithError to be called before another call has closed
the WebSocket, so this change calling didClose whether error is null or not is correct.

* Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:task:didCompleteWithError:]):

Canonical link: https://commits.webkit.org/278623@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list