components
All repositories: gitoria
4.4 KB
// #375: abrupt TLS EOF/errors must deliver close once and allow reconnect.import assert from 'node:assert/strict';import net from 'node:net';import tls from 'node:tls';import { createHash } from 'node:crypto';import { spawn, spawnSync } from 'node:child_process';import { once } from 'node:events';import { mkdtempSync, readFileSync, readlinkSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, resolve, join } from 'node:path';import { fileURLToPath } from 'node:url';const HERE = dirname(fileURLToPath(import.meta.url));const ROOT = resolve(HERE, '../../..');const BIN = process.env.HL_BIN || resolve(ROOT, 'native/zig-out/bin/hybriel');const PORT = Number(process.env.HL_TEST_PORT || 30430);const work = mkdtempSync(join(tmpdir(), 'ws-close-'));function command(cmd, args) {const r = spawnSync(cmd, args, { cwd: ROOT, encoding: 'utf8' });assert.equal(r.status, 0, r.stdout + r.stderr);}let checks = 0;try {command('openssl', ['req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-keyout', join(work, 'key.pem'), '-out', join(work, 'cert.pem'), '-days', '1', '-subj', '/CN=localhost', '-addext', 'subjectAltName=DNS:localhost']);command(BIN, ['--native', resolve(HERE, 'ws-client-close.hl'), '-o', join(work, 'client'), '--quiet']);for (const secure of [false, true]) for (const mode of ['abrupt', 'clean', 'half']) {let accepted = 0;const sockets = new Set();const timers = new Set();const handler = socket => {sockets.add(socket);socket.on('error', () => {});socket.on('close', () => sockets.delete(socket));let head = '';socket.on('data', function handshake(data) {head += data.toString();if (!head.includes('\r\n\r\n')) return;socket.removeListener('data', handshake);const key = head.match(/Sec-WebSocket-Key: (.*)/i)?.[1].trim();assert.ok(key);accepted++;socket.write('HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ' + createHash('sha1').update(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11').digest('base64') + '\r\n\r\n');// Longer than one read tick: a retryable TLS timeout must stay open.const timer = setTimeout(() => {timers.delete(timer);if (mode === 'abrupt') socket.destroy();if (mode === 'half') socket.end(); // TLS close_notify or TCP FIN, no WS closeif (mode === 'clean') socket.end(Buffer.from([0x88, 2, 3, 0xe8]));}, 700);timers.add(timer);});};const server = secure ? tls.createServer({ cert: readFileSync(join(work, 'cert.pem')), key: readFileSync(join(work, 'key.pem')), allowHalfOpen: true }, handler) : net.createServer({ allowHalfOpen: true }, handler);let child, timeout;try {server.listen(PORT, '127.0.0.1');await once(server, 'listening');child = spawn(join(work, 'client'), [`${secure ? 'wss' : 'ws'}://localhost:${PORT}/`, join(work, 'cert.pem')], { cwd: ROOT, env: process.env });let log = '';child.stdout.on('data', d => { log += d; });child.stderr.on('data', d => { log += d; });const exited = once(child, 'exit');timeout = setTimeout(() => {assert.equal(readlinkSync(`/proc/${child.pid}/cwd`), ROOT);spawnSync('ss', ['-ltnp', `sport = ${PORT}`]);child.kill('SIGKILL');}, 6000);const [code] = await exited;assert.equal(code, 0, log);assert.equal(accepted, 2, log);assert.deepEqual(log.split('\n').filter(s => /^(opened|closed|retry)/.test(s)), ['opened', `closed ${mode === 'clean' ? 1000 : 1006}`, 'retry true', 'opened', `closed ${mode === 'clean' ? 1000 : 1006}`]);checks += 3;console.log(`ok ${secure ? 'wss' : 'ws'} ${mode}: two opens, two closes, reconnect`);} finally {clearTimeout(timeout);for (const timer of timers) clearTimeout(timer);if (child && child.exitCode === null && child.signalCode === null) {assert.equal(readlinkSync(`/proc/${child.pid}/cwd`), ROOT);spawnSync('ss', ['-ltnp', `sport = ${PORT}`]);const exited = once(child, 'exit'); child.kill('SIGKILL'); await exited;}for (const socket of sockets) socket.destroy();await new Promise(r => server.close(r));}}console.log(`ok ws-client-close: ${checks} checks across 6 cases`);} finally {rmSync(work, { recursive: true, force: true });}
Branches
- b27b
- mainmain branch
- vendor-day72
- vl27-baseline
- vl27-resetkey
Latest commits
- 489afcf1virtual-list: name the scroll-position gap hybriel#445Atlas
- b7e11e3bvirtual-list: the first resetKey is the baseline, so centerId and scrollTop keep their place at mount; gate for itAtlas
- 7e428ba6Re-vendor Hybriel day72 (day73 withdrawn: minifier breaks write sets)Atlas
- a06fc778Reset virtual-list window when the host changes resetKeyAtlas
- 3aab598cRe-vendor complete Hybriel day73 set for virtual-list resetAtlas
- 337ca075MD1 gate check measures frames in the page, not milliseconds from outside, and takes the middle load (components#30)mre
- f5f131c5Record AP29 autoplay comparisons and passing gatesmre
- 51c38187Gate media autoplay on first load and after client mountmre
- a3f2223dRecord successful B44 deployment and live proofmre
- 06c1e021Record passing B44 browser rerunmre
- c9861533Record B44 component proof and browser gate blockermre
- 1b7413beIgnore detached media events and space demo option outputsmre
- ca3b4959Re-vendor complete Hybriel plugins and runtime to day44mre
- df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
- 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
- 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
- 9b872cedRecord IC28 deployment and live icon verificationmre
- 46fefaa7Count the icons entry in the offline home-page checkmre
- c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre