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

#284: Add retry-mechanism to threadsRequest-method for stability #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
11 changes: 9 additions & 2 deletions src/mibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.once("debug-ready", cb);
}

protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
protected threadsRequest(response: DebugProtocol.ThreadsResponse, request: DebugProtocol.Request, retries = 5, delay = 100): void {
if (!this.miDebugger) {
this.sendResponse(response);
return;
Expand All @@ -278,7 +278,14 @@ export class MI2DebugSession extends DebugSession {
}
this.sendResponse(response);
}).catch(error => {
this.sendErrorResponse(response, 17, `Could not get threads: ${error}`);
if (retries > 1) {
// If threads are requested too early after startup we may get the following error:
// 'Cannot execute this command while the target is running. Use the interrupt command to stop the target and try again.'
// Even without an interrupt, re-trying after some time will solve that issue in some cases.
setTimeout(() => this.threadsRequest(response, request, retries - 1, delay), delay);
} else {
this.sendErrorResponse(response, 17, `Could not get threads: ${error}`);
}
});
}

Expand Down