Skip to content

Commit

Permalink
Merge pull request #972 from project-chip/subfix
Browse files Browse the repository at this point in the history
Cherry pick Subscription clearing fix
  • Loading branch information
Apollon77 authored Jun 26, 2024
2 parents 04c34b0 + 1067826 commit 2d9f216
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The main work (all changes without a GitHub username in brackets in the below li
### __WORK IN PROGRESS__
-->

### __WORK IN PROGRESS__
* Matter-Core functionality:
* Fix: Makes sure to clear all subscriptions from the subscriber noe and not only the current session when not keeping subscriptions

### 0.9.2 (2024-06-20)
* Matter-Core functionality:
* Enhancement: Added some more certification relevant checks in Interaction server
Expand Down
4 changes: 4 additions & 0 deletions packages/matter.js/src/MatterDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ export class MatterDevice {
return { session, channel: await networkInterface.openChannel(device.addresses[0]) };
}

async clearSubscriptionsForNode(peerNodeId: NodeId, flushSubscriptions?: boolean) {
await this.#sessionManager.clearSubscriptionsForNode(peerNodeId, flushSubscriptions);
}

async close() {
this.#isClosing = true;
await this.endCommissioning();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,10 @@ export class InteractionServer implements ProtocolHandler<MatterDevice>, Interac
}

if (!keepSubscriptions) {
logger.debug(`Clear subscriptions for Session ${session.name} because keepSubscriptions=false`);
await session.clearSubscriptions(true);
logger.debug(
`Clear subscriptions for Subscriber node ${session.peerNodeId} because keepSubscriptions=false`,
);
await session.context.clearSubscriptionsForNode(session.peerNodeId, true);
}

const maxInterval = subscriptionHandler.getMaxInterval();
Expand Down
3 changes: 2 additions & 1 deletion packages/matter.js/src/session/SecureSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ export class SecureSession<T> extends Session<T> {
}

async clearSubscriptions(flushSubscriptions = false) {
for (const subscription of this.#subscriptions) {
const subscriptions = [...this.#subscriptions]; // get all values because subscriptions will remove themselves when cancelled
for (const subscription of subscriptions) {
await subscription.cancel(flushSubscriptions);
}
this.#subscriptions.length = 0;
Expand Down
8 changes: 8 additions & 0 deletions packages/matter.js/src/session/SessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ export class SessionManager<ContextT> {
}));
}

async clearSubscriptionsForNode(nodeId: NodeId, flushSubscriptions?: boolean) {
for (const session of this.#sessions) {
if (session.peerNodeId === nodeId) {
await session.clearSubscriptions(flushSubscriptions);
}
}
}

async close() {
await this.storeResumptionRecords();
for (const session of this.#sessions) {
Expand Down

0 comments on commit 2d9f216

Please sign in to comment.