Skip to content

Commit 57d2b11

Browse files
committed
fix: prevent nanosecond timestamp overflow in event repository
1 parent fbd6df3 commit 57d2b11

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

apps/webapp/app/v3/eventRepository/common.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function extractContextFromCarrier(carrier: Record<string, unknown>) {
2525
}
2626

2727
export function getNowInNanoseconds(): bigint {
28-
return BigInt(new Date().getTime() * 1_000_000);
28+
return BigInt(new Date().getTime()) * BigInt(1_000_000);
2929
}
3030

3131
export function getDateFromNanoseconds(nanoseconds: bigint): Date {
@@ -39,7 +39,7 @@ export function calculateDurationFromStart(
3939
) {
4040
const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime;
4141

42-
const duration = Number(BigInt($endtime.getTime() * 1_000_000) - startTime);
42+
const duration = Number(BigInt($endtime.getTime()) * BigInt(1_000_000) - startTime);
4343

4444
if (minimumDuration && duration < minimumDuration) {
4545
return minimumDuration;

apps/webapp/app/v3/eventRepository/index.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async function recordRunEvent(
240240
runId: foundRun.friendlyId,
241241
...attributes,
242242
},
243-
startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000),
243+
startTime: BigInt(startTime?.getTime() ?? Date.now()) * BigInt(1_000_000),
244244
...optionsRest,
245245
});
246246

apps/webapp/app/v3/runEngineHandlers.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export function registerRunEngineEventBusHandlers() {
555555
);
556556

557557
await eventRepository.recordEvent(retryMessage, {
558-
startTime: BigInt(time.getTime() * 1000000),
558+
startTime: BigInt(time.getTime()) * BigInt(1_000_000),
559559
taskSlug: run.taskIdentifier,
560560
environment,
561561
attributes: {

0 commit comments

Comments
 (0)