mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-19 00:54:32 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
A sync stuck on a dead connection held the one-at-a-time queue forever. Abandoned board polls piled up as CLOSE-WAIT sockets until the process hit its fd limit, the tokens file could no longer be opened, and a valid token read as HTTP 403. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
60 lines
1.9 KiB
Dart
60 lines
1.9 KiB
Dart
// A sync that never answers (dead connection after boot or a network blip)
|
|
// must not wedge the one-at-a-time queue: every later call, including the
|
|
// board's 4 s poll, used to wait behind it forever, abandoned connections
|
|
// piled up until the process ran out of file descriptors, and the tokens
|
|
// file became unreadable, so a valid token read as HTTP 403.
|
|
import 'dart:async';
|
|
|
|
import 'package:crdt_sync/crdt_sync.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:todo/cli/cli_session.dart';
|
|
import 'package:todo/data/note_repository.dart';
|
|
import 'package:todo/mcp/task_service.dart';
|
|
import 'package:todo/sync/sync_service.dart';
|
|
|
|
/// Hangs the first [sync] forever; later ones return at once.
|
|
class _HangsOnce extends CliSession {
|
|
_HangsOnce(NoteRepository repo, FirebaseRestClient firebase)
|
|
: super('unused', repo, firebase);
|
|
|
|
var _calls = 0;
|
|
|
|
@override
|
|
Future<SyncResult> sync({required bool push}) => _calls++ == 0
|
|
? Completer<SyncResult>().future
|
|
: Future.value(const SyncResult(mergedDevices: 0, pushed: false));
|
|
}
|
|
|
|
Future<_HangsOnce> _session() async {
|
|
final firebase = FirebaseRestClient(
|
|
databaseUrl: 'https://example.test',
|
|
auth: FirebaseTokenProvider(
|
|
apiKey: 'k',
|
|
store: InMemoryCredentialStore(
|
|
FirebaseCredentials(
|
|
idToken: 'id',
|
|
refreshToken: 'rt',
|
|
expiresAt: DateTime.utc(2099),
|
|
),
|
|
),
|
|
),
|
|
httpClient: http.Client(),
|
|
);
|
|
return _HangsOnce(await NoteRepository.openInMemory(), firebase);
|
|
}
|
|
|
|
void main() {
|
|
test(
|
|
'[T-wedge] a hung sync times out and the next call still runs',
|
|
() async {
|
|
final tasks = TaskService(
|
|
await _session(),
|
|
callTimeout: const Duration(milliseconds: 200),
|
|
);
|
|
await expectLater(tasks.list({}), throwsA(isA<TimeoutException>()));
|
|
expect(await tasks.list({}), isNotNull);
|
|
},
|
|
);
|
|
}
|