Skip to content

xarray.backends.locks.CombinedLock.locked() always returns true #10843

Closed

Description

@carlini

What happened?

The CombinedLock.locked() method incorrectly accesses lock.locked as a property instead of calling lock.locked() as a method, causing it to always return True when any locks are present, regardless of whether they are actually acquired.

def locked(self):
return any(lock.locked for lock in self.locks)

What did you expect to happen?

No response

Minimal Complete Verifiable Example

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# ]
# ///
#
# This script automatically imports the development branch of xarray to check for issues.
# Please delete this header if you have _not_ tested this script with `uv run`!

import xarray as xr
xr.show_versions()

import threading
from xarray.backends.locks import CombinedLock

# Create two threading locks
lock1 = threading.Lock()
lock2 = threading.Lock()

# Create a CombinedLock with these locks
combined = CombinedLock([lock1, lock2])

print(f"combined.locked() returns: {combined.locked()}")

Steps to reproduce

No response

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

Anything else we need to know?

I discovered this bug as part of a project where we are use LLMs to search for bugs in popular open source repositories. Before filing this bug, we paid for three expert human reviewers to validate this bug, and I also manually validated the bug on my own machines. I am confident that the bug is real, I wrote and filed this report manually, and take responsibility for this bug report.

Environment

Details

INSTALLED VERSIONS

commit: None
python: 3.13.2 | packaged by Anaconda, Inc. | (main, Feb 6 2025, 18:56:02) [GCC 11.2.0]
python-bits: 64
OS: Linux
OS-release: 6.14.0-1017-gcp
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('C', 'UTF-8')
libhdf5: None
libnetcdf: None

xarray: 2025.9.0
pandas: 2.3.2
numpy: 2.3.3
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: 24.3.1
conda: None
pytest: 8.4.2
mypy: None
IPython: None
sphinx: None

Activity

  1. added
    needs triageIssue that has not been reviewed by xarray team member
    on Oct 12, 2025
  2. dcherian commented on Oct 13, 2025

    @dcherian
    Contributor

    nice find. I wish there was a typecheker/linter rule to catch this kind of thing

  3. added and removed
    needs triageIssue that has not been reviewed by xarray team member
    on Oct 13, 2025
  4. added 2 commits that reference this issue on Dec 16, 2025
    be2a8c1
    6f7885f
  5. added a commit that references this issue on Jan 4, 2026
    018ad08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions