Skip to content

Make _delete() idempotent #5159

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

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions packages/database/src/exp/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ export class FirebaseDatabase implements _FirebaseService {
}

_delete(): Promise<void> {
this._checkNotDeleted('delete');
repoManagerDeleteRepo(this._repo, this.app.name);
this._repoInternal = null;
this._rootInternal = null;
if (this._rootInternal !== null) {
repoManagerDeleteRepo(this._repo, this.app.name);
this._repoInternal = null;
this._rootInternal = null;
}
return Promise.resolve();
}

Expand Down
12 changes: 2 additions & 10 deletions packages/storage/compat/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ import { Compat } from '@firebase/util';
* @param opt_url gs:// url to a custom Storage Bucket
*/
export class StorageServiceCompat
implements types.FirebaseStorage, Compat<StorageService> {
implements types.FirebaseStorage, Compat<StorageService>
{
constructor(public app: FirebaseApp, readonly _delegate: StorageService) {}

INTERNAL = {
/**
* Called when the associated app is deleted.
*/
delete: () => {
return this._delegate._delete();
}
};

get maxOperationRetryTime(): number {
return this._delegate.maxOperationRetryTime;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/storage/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ export class StorageService implements _FirebaseService {
* Stop running requests and prevent more from being created.
*/
_delete(): Promise<void> {
this._deleted = true;
this._requests.forEach(request => request.cancel());
this._requests.clear();
if (!this._deleted) {
this._deleted = true;
this._requests.forEach(request => request.cancel());
this._requests.clear();
}
return Promise.resolve();
}

Expand Down
6 changes: 3 additions & 3 deletions packages/storage/test/unit/service.compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ GOOG4-RSA-SHA256`
const ref = service.refFromURL('gs://mybucket/image.jpg');
const metadataPromise = ref.getMetadata();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
service.INTERNAL.delete();
service._delegate._delete();
await expect(metadataPromise).to.be.rejectedWith('storage/app-deleted');
});
it('Requests fail when started after the service is deleted', async () => {
const ref = service.refFromURL('gs://mybucket/image.jpg');
// eslint-disable-next-line @typescript-eslint/no-floating-promises
service.INTERNAL.delete();
service._delegate._delete();

await expect(ref.getMetadata()).to.be.rejectedWith('storage/app-deleted');
});
Expand All @@ -360,7 +360,7 @@ GOOG4-RSA-SHA256`
}
);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
service.INTERNAL.delete();
service._delegate._delete();
});
return toReturn;
});
Expand Down