Skip to content

Some metrics can be hidden during APC warmup #183

@b-viguier

Description

@b-viguier

Hello 👋

I was testing this library (through Artprima's SF bundle) and I discovered that during a new k8s deployment, some metrics can disappear (or be back).

According to my investigations, this is due to a race condition in the addItemToKey function:

private function addItemToKey(string $key, string $item): void
{
// Modify serialized array stored in $key
$arr = apcu_fetch($key);
if (false === $arr) {
$arr = [];
}
$_item = $this->encodeLabelKey($item);
if (!array_key_exists($_item, $arr)) {
$arr[$_item] = 1;
apcu_store($key, $arr, 0);
}
}

It reads the (array) value stored in APC, modifies it and stores it back to APC. Unfortunately, during a new deployment (in k8s) with an empty APC, several items need to be stored in APC concurrently. Then, when trying to add some new label values from 2 distinct queries, there are some chances to override one of the 2 modifications.

I didn't find any easy workaround...

Anyway, thank you very much for your work on this library 🙇

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions