fix(#831): clear region send-scope even when setting it throws

Pre-PR Gemini review (Epic #815) flagged a scope leak: setChannelSendScope was outside the try, so a lost ack after the firmware applied the scope skipped the clear, and the next unscoped channel send would ride the stale scope. Moved the set inside the try so the finally always clears. Regression test asserts a clear is attempted when the set throws.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/844-per-radio-notify
diffwireauto 1 month ago committed by Benjamin Wiechel
parent 24ca2abe3a
commit 48b39f9666

@ -4795,8 +4795,11 @@ class MeshCoreConnector extends ChangeNotifier {
'cannot derive a transport key for region "$regionName"',
);
}
await setChannelSendScope(key);
try {
// Inside the try so a lost ack on the set (the firmware may already have
// applied the scope) still runs the clear below, rather than leaking the
// scope onto the next unscoped send.
await setChannelSendScope(key);
await sendFrame(
frame,
channelSendQueueId: channelSendQueueId,

@ -69,4 +69,19 @@ void main() {
expect(sent, isEmpty);
},
);
test('a failed set-scope still attempts a clear (no scope leak)', () async {
await connector.channelRegionScopeStoreForTest.setScope(0, 'oki');
var calls = 0;
connector.sendFrameOverrideForTest = (_) {
calls++;
if (calls == 1) throw Exception('lost ack on set-scope');
};
await expectLater(
connector.sendChannelFrameScopedForTest(0, frame),
throwsA(isA<Exception>()),
);
// call 1 = set-scope (threw); call 2 = clear-scope run from the finally.
expect(calls, 2);
});
}

Loading…
Cancel
Save

Powered by TurnKey Linux.