Skip to content

Commit

Permalink
fix: race condition on data file shouldn't break combining. #1522
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 3, 2023
1 parent 85170bf commit 1f34d8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGES.rst
Expand Up @@ -20,7 +20,14 @@ development at the same time, such as 4.5.x and 5.0.
Unreleased
----------

Nothing yet.
- Fix: when using pytest-cov or pytest-xdist, or perhaps both, the combining
step could fail with ``assert row is not None`` using 7.0.2. This was due to
a race condition that has always been possible and is still possible. In
7.0.1 and before, the error was silently swallowed by the combining code.
Now it will produce a message "Couldn't combine data file" and ignore the
data file as it used to do before 7.0.2. Closes `issue 1522`_.

.. _issue 1522: https://github.com/nedbat/coveragepy/issues/1522


.. _changes_7-0-2:
Expand Down
2 changes: 2 additions & 0 deletions coverage/data.py
Expand Up @@ -161,6 +161,8 @@ def combine_parallel_data(
# The CoverageException has the file name in it, so just
# use the message as the warning.
data._warn(str(exc))
if message:
message(f"Couldn't combine data file {rel_file_name}: {exc}")
delete_this_one = False
else:
data.update(new_data, aliases=aliases)
Expand Down
2 changes: 1 addition & 1 deletion coverage/sqldata.py
Expand Up @@ -289,6 +289,7 @@ def _read_db(self) -> None:
with self._dbs[threading.get_ident()] as db:
try:
row = db.execute_one("select version from coverage_schema")
assert row is not None
except Exception as exc:
if "no such table: coverage_schema" in str(exc):
self._init_db(db)
Expand All @@ -299,7 +300,6 @@ def _read_db(self) -> None:
)
) from exc
else:
assert row is not None
schema_version = row[0]
if schema_version != SCHEMA_VERSION:
raise DataError(
Expand Down

0 comments on commit 1f34d8b

Please sign in to comment.