Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(storage): name the S3 probe failure in the fallback warning

Yudhi Armyndharis455daf723724
diff --git a/src/common/storage/storage.service.s3-reprobe.spec.ts b/src/common/storage/storage.service.s3-reprobe.spec.ts
index 4d7f46193..3050fb6fe 100644
--- a/src/common/storage/storage.service.s3-reprobe.spec.ts
+++ b/src/common/storage/storage.service.s3-reprobe.spec.ts
@@ -179,11 +179,12 @@ describe('StorageService S3 re-probe and recovery', () => {
expect(svc.isS3Available()).toBe(false);
});
- it('stays on the local fallback when the re-probe cannot create the missing bucket', async () => {
+ it('stays on the local fallback when the re-probe cannot create the missing bucket, and says why', async () => {
mockSend.mockRejectedValueOnce(s3Error('NetworkingError'));
const svc = new StorageService(makeConfig());
- warnSpyOf(svc);
+ const warn = warnSpyOf(svc);
await flush();
+ expect(warn).toHaveBeenLastCalledWith(expect.stringContaining('NetworkingError'));
mockSend.mockImplementation((cmd: unknown) =>
Promise.reject(s3Error(cmd instanceof HeadBucketCommand ? 'NoSuchBucket' : 'AccessDenied')),
@@ -191,6 +192,8 @@ describe('StorageService S3 re-probe and recovery', () => {
await jest.advanceTimersByTimeAsync(DEFAULT_S3_REPROBE_INTERVAL_MS);
expect(svc.isS3Available()).toBe(false);
+ // The store answered: the periodic warning names the refused create, not the boot-time outage.
+ expect(warn).toHaveBeenLastCalledWith(expect.stringContaining('AccessDenied'));
});
it('never transitions true→false: an S3-healthy boot ignores later transient probe failures', async () => {
diff --git a/src/common/storage/storage.service.ts b/src/common/storage/storage.service.ts
index 453be9f59..8b5be5f8d 100644
--- a/src/common/storage/storage.service.ts
+++ b/src/common/storage/storage.service.ts
@@ -132,6 +132,7 @@ export class StorageService implements OnModuleDestroy {
this.logger.log(`S3 bucket '${this.s3Bucket}' is available`);
} catch (error: unknown) {
this.logger.error('S3 bucket check failed', String(error));
+ this.lastS3Error = String(error);
this.warnLocalFallback();
}
}
@@ -163,8 +164,9 @@ export class StorageService implements OnModuleDestroy {
private warnLocalFallback(): void {
this.logger.warn(
- `S3 bucket '${this.s3Bucket}' is unreachable — media storage degraded, using the local fallback dir ` +
- `'${this.localPath}'. Re-probing every ${this.s3ReprobeIntervalMs}ms; writes return to S3 once it recovers.`,
+ `S3 bucket '${this.s3Bucket}' is unavailable (${this.lastS3Error}); media storage degraded, using the ` +
+ `local fallback dir '${this.localPath}'. Re-probing every ${this.s3ReprobeIntervalMs}ms; writes return ` +
+ 'to S3 once it recovers.',
);
}
@@ -208,6 +210,8 @@ export class StorageService implements OnModuleDestroy {
}
private lastS3Check = 0;
+ /** Why the last probe failed. The fallback warning names it: a store refusing the create is not an outage. */
+ private lastS3Error = '';
private s3CheckInFlight: Promise<void> | null = null;
/**
@@ -236,8 +240,9 @@ export class StorageService implements OnModuleDestroy {
`S3 bucket '${this.s3Bucket}' recovered — media storage back on S3. Files written to the local ` +
`fallback dir '${this.localPath}' during the outage remain there (still readable via read-through).`,
);
- } catch {
- // still unreachable — leave s3Available false; a later poll retries after the throttle window
+ } catch (error: unknown) {
+ // still unavailable: leave s3Available false; a later poll retries after the throttle window
+ this.lastS3Error = String(error);
} finally {
this.s3CheckInFlight = null;
}