Skip to content

[Messenger] Store millisecond timestamps as float instead of int to prevent int overflow issues on 32 bit based systems #44797

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

Closed
wants to merge 1 commit into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function reject(string $id): void
}
}

public function add(string $body, array $headers, int $delayInMs = 0): void
public function add(string $body, array $headers, float $delayInMs = 0): void
{
if ($this->autoSetup) {
$this->setup();
Expand All @@ -267,7 +267,7 @@ public function add(string $body, array $headers, int $delayInMs = 0): void
throw new TransportException(json_last_error_msg());
}

$score = $this->getCurrentTimeInMilliseconds() + $delayInMs;
$score = $this->getCurrentTimeInMilliseconds() + (float) $delayInMs;
$added = $this->connection->zadd($this->queue, ['NX'], $score, $message);
} else {
$message = json_encode([
Expand Down Expand Up @@ -316,9 +316,9 @@ public function setup(): void
$this->autoSetup = false;
}

private function getCurrentTimeInMilliseconds(): int
private function getCurrentTimeInMilliseconds(): float
{
return (int) (microtime(true) * 1000);
return microtime(true) * (float) 1000;
}

public function cleanup(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function send(Envelope $envelope): Envelope
$delayStamp = $envelope->last(DelayStamp::class);
$delayInMs = null !== $delayStamp ? $delayStamp->getDelay() : 0;

$this->connection->add($encodedMessage['body'], $encodedMessage['headers'] ?? [], $delayInMs);
$this->connection->add($encodedMessage['body'], $encodedMessage['headers'] ?? [], (float) $delayInMs);

return $envelope;
}
Expand Down