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

Log entry at cachelogindex-0 written to database multiple times #7

Open
tipichris opened this issue Jul 26, 2016 · 0 comments
Open

Comments

@tipichris
Copy link

I've been hacking at the code a fair bit lately and have encountered what appears to be a bug that results in one specific log entry getting written back to the database multiple times.

At first run after a cache clear, a new key is created and initialised to 0 at APC_CACHE_LOG_INDEX and $logindex is initialised to 0. Immediately afterwards we have

    if(!$added) {
        $logindex = apc_cache_key_increment($key);
    }

which doesn't increment the key or the value of $logindex because it has only just been added.

A key is then created based on $logindex, ie cachelogindex-0 and the first log entry stored there.

When the logentries are written back to the database the value stored at APC_CACHE_LOG_INDEX is reset to 0. However, when the code above is hit $added is false (because we haven't just created the key), so the value at APC_CACHE_LOG_INDEX and the value of $logindex is immediately raised to 1. Consequently, the entry at cachelogindex-0 is not overwritten, and the same, old entry is written back to the database at the next write out.

With default values, the same value will be written out every two minutes until its TTL is reached after 24 hours, ie 720 times. It's not so noticeable because the time recorded is the time of the write to the DB, not the time of the hit, so each entry is different. When I changed this behaviour to record the time of the original hit it jumped out!

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