Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZStack: fix request network address blocking all requests #1256

Merged
merged 6 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ class ZStackAdapter extends Adapter {
payload: Buffer,
disableResponse: boolean,
): Promise<ZdoTypes.RequestToResponseMap[K] | void> {
// @ts-expect-error TODO fix
return await this.sendZdoInternal(ieeeAddress, networkAddress, clusterId, payload, disableResponse, false);
}

Expand All @@ -317,7 +316,7 @@ class ZStackAdapter extends Adapter {
networkAddress: number,
clusterId: Zdo.ClusterId,
payload: Buffer,
disableResponse: true,
disableResponse: boolean,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to this "internal" function breaks proper typing, since that means it allows awaiting for response even though it shouldn't (doesn't have one for given cluster). The 2 overloads are not used anymore for the "internal" function.

skipQueue: boolean,
): Promise<void>;
private async sendZdoInternal<K extends keyof ZdoTypes.RequestToResponseMap>(
Expand Down Expand Up @@ -446,7 +445,6 @@ class ZStackAdapter extends Adapter {
disableRecovery: boolean,
sourceEndpoint?: number,
): Promise<Events.ZclPayload | void> {
logger.debug(`== sendZclFrameToEndpoint add to queue - ${ieeeAddr}/${networkAddress}`, NS);
return await this.queue.execute<Events.ZclPayload | void>(async () => {
this.checkInterpanLock();
return await this.sendZclFrameToEndpointInternal(
Expand Down
7 changes: 0 additions & 7 deletions src/utils/queue.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {logger} from './logger';

interface Job {
key?: string | number;
running: boolean;
start?: () => void;
}

const NS = 'zh:queue';

class Queue {
private jobs: Job[];
private readonly concurrent: number;
Expand All @@ -18,7 +14,6 @@ class Queue {
}

public async execute<T>(func: () => Promise<T>, key?: string | number): Promise<T> {
logger.debug(`== queue add - ${key} (keys=${this.jobs.map((j) => j.key)})`, NS);
const job: Job = {key, running: false};
this.jobs.push(job);

Expand All @@ -38,11 +33,9 @@ class Queue {
}

try {
logger.debug(`== queue execute func - ${key} (keys=${this.jobs.map((j) => j.key)})`, NS);
return await func();
} finally {
this.jobs.splice(this.jobs.indexOf(job), 1);
logger.debug(`== queue remove - ${key} (keys=${this.jobs.map((j) => j.key)})`, NS);
this.executeNext();
}
}
Expand Down
Loading