Skip to content

Commit

Permalink
quic: fix idle timeout
Browse files Browse the repository at this point in the history
After ngtcp2 being updated, `ngtcp2_conn_get_idle_timeout` is renamed as
`ngtcp2_conn_get_idle_expiry` which returns `ngtcp2_tstamp` instead of
`ngtcp2_duration`.

Refs: https://github.com/ngtcp2/ngtcp2/blob/6f40668cdce7db7c043d3a80c07f379841d8c51e/lib/ngtcp2_conn.c#L8604
PR-URL: nodejs#166
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
oyyd authored and juanarbol committed Dec 17, 2019
1 parent 7c2543c commit 579d1c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,10 @@ void QuicSession::StreamReset(

void QuicSession::UpdateIdleTimer() {
CHECK_NOT_NULL(idle_);
uint64_t timeout = ngtcp2_conn_get_idle_expiry(Connection()) / 1000000UL;
uint64_t now = uv_hrtime();
uint64_t expiry = ngtcp2_conn_get_idle_expiry(Connection());
uint64_t timeout = (expiry - now) / 1000000UL;
if (expiry < now || timeout == 0) timeout = 1;
Debug(this, "Updating idle timeout to %" PRIu64, timeout);
idle_->Update(timeout);
}
Expand Down
10 changes: 6 additions & 4 deletions test/parallel/test-quic-idle-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ const idleTimeout = common.platformTimeout(1000);
idleTimeout,
});

server.on('session', common.mustCall(() => {
client.close();
server.close();
assert(Date.now() - start < idleTimeout + error);
server.on('session', common.mustCall((serverSession) => {
serverSession.on('close', common.mustCall(() => {
client.close();
server.close();
assert(Date.now() - start < idleTimeout + error);
}));
}));

server.on('ready', common.mustCall(() => {
Expand Down

0 comments on commit 579d1c5

Please sign in to comment.