fix(#822): coalesce concurrent getDefaultFloodScope onto one query

Pre-PR Gemini review (Epic #813 T4) flagged that RESP 28 carries no correlation tag, so two concurrent getDefaultFloodScope calls could orphan the first completer. Coalesce the second caller onto the in-flight request, matching the single-in-flight guard on exportPrivateKey. (Gemini's second finding, reserveTransportCode(0xFFFF), was rejected: firmware does code-- to 0xFFFE, which the code already matches.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
epic/816-integration
diffwireauto 2 months ago committed by Strycher
parent f3d8949624
commit e531f49f51

@ -5834,6 +5834,12 @@ class MeshCoreConnector extends ChangeNotifier {
Duration timeout = const Duration(seconds: 5),
}) async {
_guardRegionScope();
// RESP 28 carries no correlation tag, so only one query can be outstanding.
// Coalesce a concurrent caller onto the in-flight request (the default scope
// is a single global value, so they want the same answer); otherwise the
// second call would orphan the first's completer to a spurious timeout.
final inFlight = _defaultFloodScopeCompleter;
if (inFlight != null) return inFlight.future;
final completer = Completer<DefaultFloodScope?>();
_defaultFloodScopeCompleter = completer;
final timer = Timer(timeout, () {

@ -167,5 +167,24 @@ void main() {
expect(sent![0], cmdSetDefaultFloodScope);
expect(sent!.length, 1 + 31 + 16);
});
test('coalesces concurrent calls onto one in-flight query', () async {
var sends = 0;
connector.sendFrameOverrideForTest = (_) {
sends++;
final b = BytesBuilder()
..addByte(respCodeDefaultFloodScope)
..add(_padName('oki', 31))
..add(Uint8List(16));
connector.handleFrameForTest(b.toBytes());
};
final f1 = connector.getDefaultFloodScope();
final f2 = connector.getDefaultFloodScope();
final r1 = await f1;
final r2 = await f2;
expect(sends, 1); // second caller did not emit a second frame
expect(r1!.name, 'oki');
expect(r2!.name, 'oki');
});
});
}

Loading…
Cancel
Save

Powered by TurnKey Linux.