Bug 240227

Summary: [WinCairo] CloseEvent has wasClean=true and no error code when the WebSocket connection got terminated from the server side
Product: WebKit Reporter: Max Schmitt <max>
Component: PlatformAssignee: Fujii Hironori <Hironori.Fujii>
Status: RESOLVED FIXED    
Severity: Normal CC: aperez, bugs-noreply, don.olmstead, Hironori.Fujii, mcatanzaro, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Other   
OS: Windows 10   
Attachments:
Description Flags
WIP patch
none
server.js none

Description Max Schmitt 2022-05-09 03:56:54 PDT
Repro:

```js
// server.js
const express = require('express');
const ws = require('ws');
const app = express();
const wsServer = new ws.Server({ noServer: true });
app.get("/", (req, res)=>res.end(`
<p>watch console</p>
<script>
function createWs(){
  const ws=new WebSocket("ws://localhost:3003/ws");
  ws.onopen = e => console.log("onopen", e);
  ws.onerror = e => console.error("onerror",e);
  ws.onclose = e => {
    console.log("onclose",e,e.code,e.wasClean);
    document.writeln("onclose with code " + e.code + " wasClean: " + e.wasClean);
  };
}
createWs();
</script>
`));
const server = app.listen(3003);
server.on('upgrade', (request, socket, head) => {
  wsServer.handleUpgrade(request, socket, head, socket => {
    socket.terminate();
  });
});
```

1. `mkdir tmp`
2. `cd tmp`
3. `npm init -y`
4. `npm install ws express`
5. `node server.js`
6. Navigate to `http://localhost:3003`

Expected (Firefox, Chromium): `onclose with code 1006 wasClean: false `
Actual (Epiphany 42.1, Custom WebKit on tip-of-tree): `onclose with code 0 wasClean: true`

Downstream bug: https://github.com/microsoft/playwright/issues/12353
Comment 1 Max Schmitt 2023-02-03 12:28:06 PST
Looks like this is fixed on Linux now and is only present in Windows.
Comment 2 Fujii Hironori 2023-02-06 13:57:23 PST
Created attachment 464871 [details]
WIP patch
Comment 3 Fujii Hironori 2023-02-06 16:35:09 PST
Created attachment 464879 [details]
server.js

WinCairo WK1 can't load the page because it has no Content-Type responose header. Modified server.js.
I confirmed WinCairo WK1 works fine.
Comment 4 Fujii Hironori 2023-02-06 17:50:56 PST
Pull request: https://github.com/WebKit/WebKit/pull/9728
Comment 5 EWS 2023-02-08 12:03:26 PST
Committed 260025@main (42847605cf96): <https://commits.webkit.org/260025@main>

Reviewed commits have been landed. Closing PR #9728 and removing active labels.
Comment 6 Radar WebKit Bug Importer 2023-02-08 12:04:22 PST
<rdar://problem/105186438>