`LocalStream::stream_lock()` reports success for unrecognized operations

Created on 12 December 2024, 6 days ago

Problem/Motivation

Attempting to acquire a lock non-blockingly from a LocalStream stream-wrapper file handle will always report success, despite failing to acquire a lock.

https://www.drupal.org/project/drupal/issues/1308054#comment-6774742 calls into question the direct return TRUE; while highlighting disconnects between in the upstream PHP documentation (for which I have raised https://github.com/php/doc-en/issues/4299 )

Steps to reproduce

In one process, acquire a lock on a stream-wrapped file and sleep; for example:

$file = fopen('temporary://testfile', 'cb');
var_dump(flock($file, LOCK_SH));
sleep(600);

In a second process attempt to acquire an exclusive lock non-blockingly (LOCK_EX | LOCK_NB) on the same file in another process, and output the result and $would_block values.

$file = fopen('temporary://testfile', 'cb');
$would_block = FALSE;
var_dump(flock($file, LOCK_EX | LOCK_NB, $would_block));
var_dump($would_block);

Expected behavior: The second process should report that it failed to acquire the lock and that it would block.
Actual behavior: The second process reports that it acquired the lock without blocking.

Proposed resolution

One or both of:

  • Update LocalStream::stream_lock() to be aware of the non-blocking modes
  • Change unrecognized operations in LocalStream::stream_lock() to return FALSE;

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

file system

Created by

🇨🇦Canada adam-vessey PE, Canada

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

Comments & Activities

Production build 0.71.5 2024