Registering a YAML converter while another thread serializes no longer throws #354

Closed
opened 2026-11-06 15:33:04 -05:00 by claude · 0 comments
Owner
  • Draft: none (found in develop run 1282, 2026-11-06)
  • Priority: medium (a shared NuGet library; it turned develop red)
  • Agent: main session
  • Depends on: none
  • Decisions: none

Why

YamlSerializer keeps its converters in a static List<IYamlTypeConverter>. AddConverter adds to it with no lock, while GetDeserializer and GetSerializer enumerate it with List.ForEach.

  • Develop run 1282 failed YamlInputFormatterTests.ReadRequestBodyAsync_ValidYaml_ReturnsDeserializedValue with InvalidOperationException: Collection was modified at YamlSerializer.GetDeserializer (line 144).
  • Any host that adds a converter while requests are served can hit it. JsonSerializer already guards its list with a lock and enumerates a snapshot.

What changes

  • YamlSerializer guards the list with a lock in AddConverter, and the builders enumerate a snapshot taken under it, as JsonSerializer does.
  • A concurrency test adds 400 distinct converters on 8 threads while 8 more build serializers.

Acceptance

  • The new test fails without the fix (3 of 5 runs failed) and passes with it.
  • The whole solution passes on Linux.
- **Draft:** none (found in develop run 1282, 2026-11-06) - **Priority:** medium (a shared NuGet library; it turned develop red) - **Agent:** main session - **Depends on:** none - **Decisions:** none ### Why `YamlSerializer` keeps its converters in a static `List<IYamlTypeConverter>`. `AddConverter` adds to it with no lock, while `GetDeserializer` and `GetSerializer` enumerate it with `List.ForEach`. - Develop run 1282 failed `YamlInputFormatterTests.ReadRequestBodyAsync_ValidYaml_ReturnsDeserializedValue` with `InvalidOperationException: Collection was modified` at `YamlSerializer.GetDeserializer` (line 144). - Any host that adds a converter while requests are served can hit it. `JsonSerializer` already guards its list with a lock and enumerates a snapshot. ### What changes - `YamlSerializer` guards the list with a lock in `AddConverter`, and the builders enumerate a snapshot taken under it, as `JsonSerializer` does. - A concurrency test adds 400 distinct converters on 8 threads while 8 more build serializers. ### Acceptance - [ ] The new test fails without the fix (3 of 5 runs failed) and passes with it. - [ ] The whole solution passes on Linux.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#354
No description provided.