The list of last requests hashes from thGetLastRequestsHashes and stubGetLastRequestsHashes can miss some requests because of the race condition

Created on 26 February 2025, 2 months ago

Problem/Motivation

The module uses Drupal State API to store the list of the last requests hashes, and simply appends the last request to the stored list.

But in some cases when we have multiple parallel requests to Drupal, we can face the race condition and the values can be overwritten by another parallel request between "get" and "set" here:

  protected function stubStoreRequestHash(string $hash): void {
    parent::stubStoreRequestHash($hash);
    $lastHashes = $this->state->get(self::STATE_KEY_LAST_REQUESTS_HASHES, []);
    array_unshift($lastHashes, $hash);
    $lastHashes = array_slice($lastHashes, 0, self::LAST_REQUESTS_HASHES_STORE_LIMIT);
    $this->state->set(self::STATE_KEY_LAST_REQUESTS_HASHES, $lastHashes);
  }

Steps to reproduce

Run a test that executes multiple parallel requests to Drupal.

See that the tests are not stable and sometimes miss the stored response hashes.

Proposed resolution

Use a locking mechanism to prevent overwriting the values.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.5

Component

Code

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024