Skip to content

Commit

Permalink
fix 10 failures
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Sep 7, 2024
1 parent 5ca06c6 commit deae218
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/web/websocket/stream/websocketstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { channels } = require('../../../core/diagnostics')
const { WebsocketFrameSend } = require('../frame')
const { ByteParser } = require('../receiver')
const { WebSocketError } = require('./websocketerror')
const { utf8DecodeBytes, readableStreamClose } = require('../../fetch/util')
const { utf8DecodeBytes } = require('../../fetch/util')

class WebSocketStream {
// Each WebSocketStream object has an associated url , which is a URL record .
Expand Down Expand Up @@ -370,11 +370,11 @@ class WebSocketStream {
// 6. If the connection was closed cleanly ,
if (wasClean) {
// 6.1. Close stream ’s readable stream .
readableStreamClose(this.#readableStreamController)
this.#readableStream.cancel().catch(() => {})

// 6.2. Error stream ’s writable stream with an " InvalidStateError " DOMException indicating that a closed WebSocketStream cannot be written to.
if (!this.#writableStream.locked) {
this.#writableStream.abort(new WebSocketError('A closed WebSocketStream cannot be written to'))
this.#writableStream.abort(new DOMException('A closed WebSocketStream cannot be written to', 'InvalidStateError'))
}

// 6.3. Resolve stream ’s closed promise with WebSocketCloseInfo «[ " closeCode " → code , " reason " → reason ]».
Expand Down
14 changes: 14 additions & 0 deletions test/wpt/server/websocket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ wss.on('connection', (ws, request) => {
const protocol = line.split(',')[0]
ws.send(protocol)
return
} else if (request.url === '/remote-close' || request.url.startsWith('/remote-close?')) {
const fullUrl = new URL(request.url, `ws://localhost:${server.address().port}`)

const code = fullUrl.searchParams.has('code') ? Number(fullUrl.searchParams.get('code')) : undefined
const reason = fullUrl.searchParams.get('reason') ?? undefined
const abrupt = fullUrl.searchParams.get('abrupt') === '1'

if (abrupt) {
ws._socket.end()
return
}

ws.close(code, reason)
return
}

ws.on('message', (data, isBinary) => {
Expand Down

0 comments on commit deae218

Please sign in to comment.