Skip to content

Commit 229f4d9

Browse files
committed
wip: checking leaky connections
1 parent 73f58cc commit 229f4d9

File tree

6 files changed

+73
-71
lines changed

6 files changed

+73
-71
lines changed

Cargo.lock

Lines changed: 25 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ lto = false
1414
codegen-units = 1
1515
incremental = false
1616

17-
[profile.dev]
18-
debug = true
19-
strip = false
20-
opt-level = 0
21-
lto = false
22-
codegen-units = 1
23-
incremental = false
24-
2517
[lib]
2618
crate-type = ["cdylib"]
2719
path = "src/native/napi/lib.rs"

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@matrixai/errors": "^2.1.3",
5757
"@matrixai/events": "^4.0.1",
5858
"@matrixai/id": "^4.0.0",
59-
"@matrixai/logger": "^4.0.4-alpha.5",
59+
"@matrixai/logger": "^4.0.3",
6060
"@matrixai/resources": "^2.0.1",
6161
"@matrixai/timer": "^2.1.1",
6262
"ip-num": "^1.5.0"
@@ -96,8 +96,5 @@
9696
"tsx": "^3.12.7",
9797
"typedoc": "^0.24.8",
9898
"typescript": "^5.1.6"
99-
},
100-
"overrides": {
101-
"@matrixai/logger": "^4.0.4-alpha.5"
10299
}
103100
}

scripts/memtest.mjs

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ async function generateTLSConfig() {
306306
};
307307
}
308308

309+
// setInterval(() => console.log("Im still alive!"), 5000);
310+
309311
/* eslint-disable no-console */
310312
const main = async () => {
311313
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.WARN, [
@@ -322,8 +324,7 @@ const main = async () => {
322324
const clientCrypto = {
323325
randomBytes: (data) => webcrypto.getRandomValues(new Uint8Array(data)),
324326
};
325-
const message = Buffer.from('The Quick Brown Fox Jumped Over The Lazy Dog');
326-
const connectionEventProm = utils.promise();
327+
let connectionEventProm = utils.promise();
327328
const tlsConfig = await generateTLSConfig();
328329
const server = new QUICServer({
329330
crypto: {
@@ -342,45 +343,51 @@ const main = async () => {
342343
connectionEventProm.resolveP(e),
343344
);
344345
await server.start({ host: '127.0.0.1' });
345-
const client = await QUICClient.createQUICClient({
346-
host: '127.0.0.1',
347-
port: server.port,
348-
localHost: '127.0.0.1',
349-
crypto: {
350-
ops: clientCrypto,
351-
},
352-
logger: logger.getChild(QUICClient.name),
353-
config: {
354-
verifyPeer: false,
355-
},
356-
});
357-
socketCleanMethods.extractSocket(client);
358-
const conn = (await connectionEventProm.p).detail;
359-
const activeServerStreams = [];
360-
conn.addEventListener(
361-
events.EventQUICConnectionStream.name,
362-
(streamEvent) => {
363-
const stream = streamEvent.detail;
364-
const streamProm = stream.readable.pipeTo(stream.writable);
365-
activeServerStreams.push(streamProm);
366-
},
367-
);
368346

369-
for (let i = 0; i < 1000; i++) {
370-
console.error('loop');
347+
const data = Buffer.alloc(1, 0xf0);
348+
349+
for (let i = 0; i < 100000; i++) {
350+
// if (i % 500 == 0) console.error('loop', i);
351+
console.error('loop', i);
352+
353+
connectionEventProm = utils.promise();
354+
const client = await QUICClient.createQUICClient({
355+
host: '127.0.0.1',
356+
port: server.port,
357+
localHost: '127.0.0.1',
358+
crypto: {
359+
ops: clientCrypto,
360+
},
361+
logger: logger.getChild(QUICClient.name),
362+
config: {
363+
verifyPeer: false,
364+
},
365+
});
366+
socketCleanMethods.extractSocket(client);
367+
const conn = (await connectionEventProm.p).detail;
368+
let activeStream = undefined;
369+
conn.addEventListener(
370+
events.EventQUICConnectionStream.name,
371+
(streamEvent) => {
372+
const stream = streamEvent.detail;
373+
const streamProm = stream.readable.pipeTo(stream.writable);
374+
activeStream = streamProm;
375+
},
376+
{ 'once': true },
377+
);
378+
371379
const stream = client.connection.newStream();
372380
const writer = stream.writable.getWriter();
373-
await writer.write(message);
381+
await writer.write(data);
374382
await writer.close();
375-
const reader = stream.readable.getReader();
376-
let finished = false;
377-
while (!finished) {
378-
finished = (await reader.read()).done;
383+
for await (const _ of stream.readable) {
384+
// do nothing
379385
}
386+
await activeStream;
387+
await conn.stop({ force: true });
388+
await client.destroy({ force: true });
380389
}
381-
await Promise.all([activeServerStreams]);
382390

383-
await client.destroy({ force: true });
384391
await server.stop({ force: true });
385392
console.error('Test passed!');
386393
};

src/QUICConnection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ class QUICConnection {
790790
// Expect the `data` is mutated here due to in-place decryption,
791791
// so do not re-use the `data` afterward.
792792
this.conn.recv(data, recvInfo);
793+
// this.logger.warn(`recv: ${data.byteLength}`);
793794
} catch (e) {
794795
// If `config.verifyPeer` is true and `config.verifyCallback` is undefined,
795796
// then during the TLS handshake, a `TlsFail` exception will only be thrown
@@ -891,6 +892,7 @@ class QUICConnection {
891892
// Fastest way of allocating a buffer, which will be dispatched
892893
const sendBuffer = Buffer.allocUnsafe(this.config.maxSendUdpPayloadSize);
893894
try {
895+
// this.logger.warn(`send: ${sendBuffer.byteLength}`);
894896
const result = this.conn.send(sendBuffer);
895897
if (result === null) {
896898
// Break the loop

0 commit comments

Comments
 (0)