Skip to content

Commit 48eb47d

Browse files
committed
log when socket times out
1 parent e0fa27c commit 48eb47d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/metrics/dogstatsd.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ export class LambdaDogStatsD {
7878
/** Block until all in-flight sends have settled */
7979
public async flush(): Promise<void> {
8080
const allSettled = Promise.allSettled(this.pendingSends);
81-
const maxTimeout = new Promise((resolve) => setTimeout(resolve, LambdaDogStatsD.MAX_FLUSH_TIMEOUT));
81+
const maxTimeout = new Promise<"timeout">((resolve) => {
82+
setTimeout(() => resolve("timeout"), LambdaDogStatsD.MAX_FLUSH_TIMEOUT);
83+
});
84+
85+
const winner = await Promise.race([allSettled, maxTimeout]);
86+
if (winner === "timeout") {
87+
logDebug("Timed out before sending all metric payloads");
88+
}
8289

83-
await Promise.race([allSettled, maxTimeout]);
8490
this.pendingSends.clear();
8591
}
8692
}

0 commit comments

Comments
 (0)