Repository navigation
quic: update writedesiredsize on maxdataframe - #65306
martenrichter wants to merge 5 commits into
Conversation
|
Review requested:
|
|
I have just committed a PR to ngtcp2/ngtcp2#2283 . |
cb2e8dd to
0d83b2d
Compare
|
An ngtcp2 version with the change has just been released. @pimterry @jasnell |
|
It's updated by a weekly CI job (https://github.com/nodejs/node/actions/workflows/tools.yml), I've just manually triggered it for ngtcp2 though, PR is here: #67257 |
0d83b2d to
a2599f7
Compare
|
Rebased and ready for review. (If tests are passing). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65306 +/- ##
==========================================
+ Coverage 90.57% 90.58% +0.01%
==========================================
Files 802 802
Lines 287027 287027
Branches 55427 55425 -2
==========================================
+ Hits 259965 259998 +33
+ Misses 17154 17112 -42
- Partials 9908 9917 +9 🚀 New features to boost your workflow:
|
| // The peer granted more flow control for session. Re-schedule | ||
| // all streams so SendPendingData will resume writing. | ||
| for (auto& [id, stream] : session().streams()) { | ||
| stream->Schedule(&stream_queue_); |
There was a problem hiding this comment.
| stream->Schedule(&stream_queue_); | |
| stream->Schedule(&stream_queue_); | |
| stream->UpdateWriteDesiredSize(); |
Do you need to update the stream size here like you do in http3.cc?
There was a problem hiding this comment.
Good question. Waiting of the upstream update took a long time, so it is hard to remember. I remember, that I had this change and that the mechanics of http/3 and non http/3 was different. I will try to write a test for this case, and see if it is required.
There was a problem hiding this comment.
I tested it, at least with the test, I could not provoke it. I copied the test for http/3, added an alpn, and used the full window size as we have no framing in non http/3. I think the difference is that no lib is inbetween and another trigger is causing, that writeDesiredSize is updated. But I am pretty sure, I have looked more into it when I wrote the patch.
There was a problem hiding this comment.
But it may be the full window size is not the correct trigger. Do we have other traffic I need to include? I ask @pimterry , who provided the initial test for the related streammaxdata bug.
| max_data); | ||
| for (auto& [id, stream] : session().streams()) { | ||
| stream->UpdateWriteDesiredSize(); // the stream might be blocked | ||
| // on js side, is unblock stream also required? |
There was a problem hiding this comment.
Are you looking for an answer to this in this PR or is this more of a follow up?
There was a problem hiding this comment.
No, it is more like a hint, where to look, if we experience other stalls. Currently, the test indicate that unblock in this pattern is not required.
pimterry
left a comment
There was a problem hiding this comment.
I'm fairly sure this doesn't cover the raw QUIC case. Here's a QUIC repro, which I think should pass, if everything works correctly but fails with this change:
import * as assert from 'node:assert';
import { listen, connect } from 'node:quic';
import { readFileSync } from 'node:fs';
import { createPrivateKey } from 'node:crypto';
import { setImmediate, setTimeout as sleep } from 'node:timers/promises';
const tls = {
keys: [createPrivateKey(readFileSync('test/fixtures/keys/agent1-key.pem'))],
certs: [readFileSync('test/fixtures/keys/agent1-cert.pem')],
};
const WINDOW = 4096;
const serverRead = Promise.withResolvers();
// Server: holds the data unread (so no MAX_DATA window updates) until told to read.
const endpoint = await listen((session) => {
session.onstream = async (stream) => {
await serverRead.promise;
for await (const _ of stream);
};
}, { alpn: 'x', sni: { '*': tls }, transportParams: { initialMaxData: WINDOW } });
const session = await connect(endpoint.address, { alpn: 'x', verifyPeer: 'manual' });
const stream = session.createBidirectionalStream();
const writer = stream.writer;
// Fill the connection window exactly.
writer.writeSync(new Uint8Array(WINDOW));
// Wait for ack, so nothing is in flight.
while (stream.stats.maxOffsetAcknowledged < WINDOW) await setImmediate();
console.log('window full, canWrite:', writer.canWrite); // false, as expected
// Server reads -> sends MAX_DATA -> window reopens.
serverRead.resolve();
// Wait for the writer to drain, or give up after 1s if it never does.
await writer[Symbol.for('Stream.drainableProtocol')]();
// If the client handles MAX_DATA correctly, this should be true:
assert.ok(writer.canWrite, 'window should have reopened');
process.exit(0);Also, from what I can see I think streams aren't actually unscheduled or blocked when the whole session window runs out (only when stream windows do). All we need to do is update the session window, so we can simplify things here. That means:
- We shouldn't (I think...) need to call
stream->Scheduleat all. - All we'd need is the loop over
session->streams()to update writeDesiredSize when the callback fires, just this:for (auto& [id, stream] : session->streams()) { if (session->is_destroyed()) break; stream->UpdateWriteDesiredSize(); }
- We don't need to go through the
Applicationlayer like this does. This fix can happen directly in the generic Session layer, without needing two separate implementations. There's nothing protocol-specific about this, so the implementations would be identical, I think we can keep it simple instead.
Not fully tested, but as an outline I think that should work and fix this for HTTP/3 and raw QUIC too.
Does that make sense?
a2599f7 to
82934b8
Compare
|
@pimterry |
|
@martenrichter node-test-linter is failing on both tests with |
Interesting and the other linter (the non jenkins) will not let it through without it. Let's see if you have an idea to fix it without the eslint directive, |
|
Found it! The lint rules on main changed yesterday, in f5d4cd3 If you rebase and drop the |
This commit will react on a callback from ngtcp2, when a maxdata frame arrives and update the scheduled streams accordingly. A PR to get this callback is pending. Fixes: nodejs#64835 Signed-off-by: Marten Richter <marten.richter@freenet.de>
Co-authored-by: Tim Perry <pimterry@gmail.com>
31bcdc4 to
d910b2d
Compare
|
@pimterry Thanks! That was really bad timing. I have just removed the eslint directives and rebased. |
This commit will react on a callback from
ngtcp2, when a maxdata frame arrives and
update the scheduled streams accordingly.
A PR to get this callback is pending.
Fixes: #64835