Skip to content

Исправление гонки при параллельном чтении системного перечисления (#1734) - #1736

Merged
EvilBeaver merged 2 commits into
developfrom
cursor/fix-enum-concurrent-read-b6e3
Sep 15, 2026
Merged

EvilBeaver merged 2 commits into
developfrom
cursor/fix-enum-concurrent-read-b6e3

Conversation

@EvilBeaver

@EvilBeaver EvilBeaver commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Проблема

При первом одновременном обращении из фоновых заданий к значению системного перечисления (например, НаправлениеПоиска.СКонца) возникал System.IndexOutOfRangeException внутри HashSet.Add.

Причина: EnumerationContext.WarnDeprecation() помечал уже проверенные свойства в общем HashSet<int> без синхронизации. HashSet<T> не поддерживает конкурентную запись.

Fixes #1734

Решение

Набор проверенных свойств заменён на ConcurrentDictionary<int, byte>. Первое обращение к свойству атомарно фиксируется через TryAdd, повторные чтения не гоняются за общим изменяемым HashSet.

Поведение предупреждений об устаревших значениях не меняется: сообщение по-прежнему пишется один раз.

Тесты

  • C#: параллельное чтение обычного и устаревшего значения перечисления
  • BSL: 200 фоновых заданий одновременно читают НаправлениеПоиска.СКонца
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when enumeration values are accessed concurrently.
    • Prevented errors during parallel reads of system and deprecated enumeration values.
    • Deprecated enumeration values now emit a single warning even when accessed simultaneously.
  • Tests

    • Added coverage for concurrent enumeration access, warning behavior, and parallel system enumeration reads.

)

HashSet в EnumerationContext.WarnDeprecation не потокобезопасен:
при одновременном первом обращении из фоновых заданий возникал IndexOutOfRangeException.

Co-authored-by: Andrei Ovsiankin <EvilBeaver@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 27cce415-010e-47c3-9f2f-e8d824d7cc74

📥 Commits

Reviewing files that changed from the base of the PR and between 96a6115 and 9df5d11.

📒 Files selected for processing (3)
  • src/ScriptEngine/Machine/Contexts/EnumerationContext.cs
  • src/Tests/OneScript.Core.Tests/ObsoleteMembersTest.cs
  • tests/tasks.os

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change replaces unsynchronized deprecation tracking with ConcurrentDictionary<int, byte>. It adds C# and script tests for concurrent enumeration access, including single-warning verification for deprecated values.

Changes

Enumeration concurrency

Layer / File(s) Summary
Thread-safe deprecation tracking
src/ScriptEngine/Machine/Contexts/EnumerationContext.cs
WarnDeprecation uses ConcurrentDictionary.TryAdd to register each property once before evaluating and logging deprecation information.
Concurrent access validation
src/Tests/OneScript.Core.Tests/ObsoleteMembersTest.cs, tests/tasks.os
Tests perform parallel reads of deprecated and system enumeration values. They verify successful access, no exceptions, no unexpected warnings, and one warning for the deprecated value.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 9df5d

The concurrent enumeration-read path now uses thread-safe deprecation tracking, with added parallel-access coverage. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Заголовок точно описывает основное изменение: исправление гонки при параллельном чтении системного перечисления.
Linked Issues check ✅ Passed Требование issue #1734 выполнено. EnumerationContext.WarnDeprecation() использует ConcurrentDictionary<int, byte> и TryAdd, поэтому только один поток регистрирует первое обращение без конкурентн…
Out of Scope Changes check ✅ Passed Изменения соответствуют issue #1734. Они включают исправление потокобезопасности и связанные автоматические тесты в C# и BSL. Несвязанных изменений в представленном составе PR нет.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/fix-enum-concurrent-read-b6e3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EvilBeaver
EvilBeaver marked this pull request as ready for review September 15, 2026 12:04
@sonar-openbsl-ru-qa-bot

Copy link
Copy Markdown

@EvilBeaver
EvilBeaver merged commit 74ce572 into develop Sep 15, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Гонка при параллельном чтении значения системного перечисления

2 participants