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

Exit on disabled database #245

Merged
merged 7 commits into from
May 7, 2024
Merged
Changes from 3 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
16 changes: 15 additions & 1 deletion packages/sdk-core/src/modules/database/BacktraceDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class BacktraceDatabase implements BacktraceModule {
return this._enabled;
}

/**
* Abort controller to cancel asynchronous database operations when
* the database is being disabled by the user.
*/
private readonly _abortController = new AbortController();

private readonly _databaseRecordContext: BacktraceDatabaseContext;
private readonly _storageProviders: BacktraceDatabaseStorageProvider[] = [];

Expand Down Expand Up @@ -158,6 +164,7 @@ export class BacktraceDatabase implements BacktraceModule {
public dispose() {
this._enabled = false;
clearInterval(this._intervalId);
this._abortController.abort();
}

/**
Expand Down Expand Up @@ -206,12 +213,19 @@ export class BacktraceDatabase implements BacktraceModule {
const records = [...this._databaseRecordContext.getBucket(bucketIndex)];

for (const record of records) {
if (!this.enabled) {
return;
}
if (record.locked) {
continue;
}
try {
record.locked = true;
const result = await this._requestHandler.send(record.data, record.attachments);
const result = await this._requestHandler.send(
record.data,
record.attachments,
this._abortController.signal,
);
if (result.status === 'Ok') {
this.remove(record);
continue;
Expand Down
Loading