Skip to content
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

Possible Race Condition in APC::updateHistogram #140

Open
skyellin opened this issue Dec 12, 2023 · 0 comments
Open

Possible Race Condition in APC::updateHistogram #140

skyellin opened this issue Dec 12, 2023 · 0 comments

Comments

@skyellin
Copy link

We have noticed that our application occasionally times out. When this happens, logs nearly always indicate that the script stopped execution at "promphp/prometheus_client_php/src/Prometheus/Storage/APC.php on line 72" (sometimes line 71).

This is the following block inside \Prometheus\Storage\APC::updateHistogram

// Atomically increment the sum
// Taken from https://github.com/prometheus/client_golang/blob/66058aac3a83021948e5fb12f1f408ff556b9037/prometheus/value.go#L91
$done = false;
while (!$done) {
    $old = apcu_fetch($sumKey);
    if ($old !== false) {
        $done = apcu_cas($sumKey, $old, $this->toBinaryRepresentationAsInteger($this->fromBinaryRepresentationAsInteger($old) + $data['value']));
    }
}

My very superficial understanding leads me to believe that apcu_cas may be unlikely to return true if another process (or many processes) are also continuously updating the value stored at $sumKey, since $old may no longer match the persisted value.

Do you see any cause for concern or is my analysis incorrect?

@skyellin skyellin changed the title Possible Race Condition in updateHistogram Possible Race Condition in APC::updateHistogram Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant