Skip to content
Closed
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
4 changes: 2 additions & 2 deletions internal-packages/replication/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class LogicalReplicationClient {
} else if (buffer[0] === 0x6b) {
// Primary keepalive message
const timestamp = Math.floor(
buffer.readUInt32BE(9) * 4294967.296 + buffer.readUInt32BE(13) / 1000 + 946080000000
buffer.readUInt32BE(9) * 4294967.296 + buffer.readUInt32BE(13) / 1000 + 946684800000
);
const shouldRespond = !!buffer.readInt8(17);
this.events.emit("heartbeat", { lsn, timestamp, shouldRespond });
Expand Down Expand Up @@ -658,7 +658,7 @@ export class LogicalReplicationClient {
const slice = lsn.split("/");
let [upperWAL, lowerWAL]: [number, number] = [parseInt(slice[0], 16), parseInt(slice[1], 16)];
// Timestamp as microseconds since midnight 2000-01-01
const now = Date.now() - 946080000000;
const now = Date.now() - 946684800000;
const upperTimestamp = Math.floor(now / 4294967.296);
const lowerTimestamp = Math.floor(now - upperTimestamp * 4294967.296);
if (lowerWAL === 4294967295) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class FairQueueSelectionStrategy implements RunQueueSelectionStrategy {

// Add selected item to result and remove from items
result.push(items[index].envId);
totalWeight -= items[index].weight;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 totalWeight fix matches existing pattern in #weightedRandomQueueOrder but variable is declared const

The addition of totalWeight -= items[index].weight; at line 229 is the correct fix for the weighted shuffle algorithm — without it, this._rng() * totalWeight on line 217 uses a stale total after items are removed, biasing selection toward later items in the array. The analogous method #weightedRandomQueueOrder at lines 293-310 correctly uses let totalWeight and decrements it at line 309. However, totalWeight in #weightedShuffle is declared as const at line 212, while the new line 229 attempts to reassign it. The declaration should be let to match the pattern in the analogous method.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

items.splice(index, 1);
}

Expand Down