Skip to content

Commit 8ca9bfc

Browse files
committed
Refresh on keepalive
1 parent 0c63d69 commit 8ca9bfc

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

crates/core/src/sync/streaming_sync.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ impl StreamingSyncIteration {
389389
SyncStateMachineTransition::DataLineSaved { line: data_line }
390390
}
391391
SyncLine::KeepAlive(token) => {
392+
self.adapter.increase_ttl(&self.options.active_streams)?;
393+
392394
if token.is_expired() {
393395
// Token expired already - stop the connection immediately.
394396
event

dart/test/sync_stream_test.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ void main() {
372372
});
373373

374374
syncTest('increase ttl', (controller) {
375+
const startTime = 1740826800;
376+
375377
control(
376378
'subscriptions',
377379
json.encode({
@@ -383,7 +385,7 @@ void main() {
383385
);
384386

385387
var [row] = db.select('SELECT * FROM ps_stream_subscriptions');
386-
expect(row, containsPair('expires_at', 1740826800));
388+
expect(row, containsPair('expires_at', startTime));
387389

388390
controller.elapse(const Duration(minutes: 30));
389391

@@ -399,15 +401,22 @@ void main() {
399401

400402
// Which should increase its expiry date.
401403
[row] = db.select('SELECT * FROM ps_stream_subscriptions');
402-
expect(row, containsPair('expires_at', 1740828600));
404+
expect(row, containsPair('expires_at', startTime + 1800));
405+
406+
// The sync client uses token_expires_in lines to extend the expiry date
407+
// of active stream subscriptions.
408+
controller.elapse(const Duration(minutes: 30));
409+
control('line_text', json.encode({'token_expires_in': 3600}));
410+
411+
[row] = db.select('SELECT * FROM ps_stream_subscriptions');
412+
expect(row, containsPair('expires_at', startTime + 3600));
403413

404-
// Stopping should not increase the expiry date. Client SDKs will do that
405-
// periodically.
414+
// Stopping should not increase the expiry date.
406415
controller.elapse(const Duration(minutes: 30));
407416
control('stop', null);
408417

409418
[row] = db.select('SELECT * FROM ps_stream_subscriptions');
410-
expect(row, containsPair('expires_at', 1740828600));
419+
expect(row, containsPair('expires_at', startTime + 3600));
411420
});
412421

413422
syncTest('can be made implicit', (_) {

0 commit comments

Comments
 (0)