Report a lane enqueue or SynchronizationContext.Post from a non-simulation thread as a deterministic failure
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 43/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- distributed-systems, testing
Hướng nghiên cứu
Start by reading SimulationSchedulerLane.Enqueue, SimulationSynchronizationContext.Post and Send, and SimulationScheduler.RegisterCore; the issue identifies these as candidate points for detecting off-thread operation registration. Trace how RunStep surfaces failures and how the driver reports stalls or completion. Done means an off-thread post fails deterministically with its escaping stack, including when it arrives late.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Work posted into a simulation from a thread outside it is accepted silently today. SimulationSchedulerLane.Enqueue (and so SimulationSynchronizationContext.Post) succeeds on a real thread-pool thread. Its SingleThreadedGuard detects only concurrent entry, so the post becomes an operation that no seed decides.
The run then goes wrong in one of two ways:
- It diverges silently. The recorded schedule replays only up to the point where the operation appeared.
- It stalls spuriously. If the post lands after the driver's
RunStepreturnedfalse,TryAdvanceVirtualTimedeclines, because something is now runnable. The driver then sees nothing runnable and no timer pending, whileDescribeLiveness()reportsrunnable 1orExternallyCompletable.
The existing affinity check doesn't catch this. The escaped thread carries no simulation runtime context, so no controlled API reports a SimulationThreadAffinityException.
This was found in ReubenBond/clog#360 and fixed there on the consumer side in ReubenBond/clog#361.
Minimal reproduction
The escape needs unrewritten code (for example a simulation test assembly, which the build doesn't rewrite) that awaits a BCL task combinator over a task that runs its continuations asynchronously:
// In the (unrewritten) test assembly, inside a scenario started on a lane:
var answered = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var never = new TaskCompletionSource();
var any = Task.WhenAny(answered.Task, never.Task); // the BCL's combinator, not ControlledTask.WhenAny
bool? inside = null;
_ = any.ContinueWith(_ => inside = scheduler.IsSimulationThread,
CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
answered.SetResult();
await any; // the continuation is posted to the lane's SynchronizationContext from a .NET TP Worker
never.SetResult();
// inside == false, every run.
Here is why the BCL escapes. Task.RunContinuations doesn't run an ITaskCompletionAction whose InvokeMayRunArbitraryCode is true inline when the completing task has RunContinuationsAsynchronously. It queues it to the thread pool instead, and that includes the TwoTaskWhenAnyPromise. The promise then completes any on the pool, and the await continuation is posted to the lane from that thread.
A diagnostic build logged the stack of every operation registered while !IsSimulationThread. Each one was:
SimulationScheduler.RegisterCore
SimulationScheduler.Schedule / ScheduleAfter
SimulationSchedulerLane.Schedule / Enqueue(ScheduledItem)
SimulationSynchronizationContext.Post
System.Threading.Tasks.AwaitTaskContinuation.RunCallback
System.Threading.Tasks.Task.RunContinuations
System.Threading.Tasks.Task`1.TrySetResult
System.Threading.Tasks.Task.TwoTaskWhenAnyPromise`1.Invoke
System.Threading.ThreadPoolWorkQueue.Dispatch (".NET TP Worker")
Proposed hardening
When a lane enqueue, and so SimulationSynchronizationContext.Post/Send, comes from a thread that isn't one of the scheduler's operation threads and doesn't hold its control scope (!IsSimulationThread):
- Record it as a thread-affinity violation, as
ReportThreadAffinityViolationdoes for controlled APIs. - Have the driving thread's next
RunStepsurface it, so the run fails with the escaping stack rather than diverging or stalling.
A second check would make the failure deterministic even when the escaped thread posts late. When the driver reports a stall or finishes, it could check whether any operation was registered off the simulation thread since the last step.
Possibly related: RegisterCore (and ScheduleAfter's timer path) is the common point where any operation is created, so one check there would cover lanes, timers, and direct Schedule calls alike.
Consumer-side fix, for reference
ReubenBond/clog#361 bans the BCL's Task.WhenAll, Task.WhenAny and Task.WhenEach in simulation test projects, and routes them through a rewritten helper that binds to ControlledTask's combinators. The hardening proposed here would turn any similar escape (Task.Yield or an await with no synchronization context, a raw ThreadPool call, and so on) into an immediate, attributable failure.
- Ngôn ngữ chính
- C#
- Star
- 0
- Fork
- 0
- Merge trung bình
- 2 giờ 32 phút
- Pull request đã merge (30 ngày)
- 23
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ReubenBond/Clockwork
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ReubenBond/Clockwork#73 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
ReubenBond/Clockwork#70 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
ReubenBond/Clockwork#77 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
ReubenBond/Clockwork#78 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
ReubenBond/Clockwork#69 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ReubenBond/Clockwork
Issue tương tự
-
[Bug]: Threading.Analyzers 0.7.79 does not load on the .NET 10 SDK (CS9057), CHT rules silently offĐang mởbug regression threading
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
CryptoHives/Foundation#362 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: 本地歌词翻译显示错误Đang mởbug need-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Fervent-Tempo/AF-Media-Bar#321 ·
-
a-corriger documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 87/100
christian-raj/S-Aloha#345 ·
-
bug 要トリアージ
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
worldInstancedOccluderNode reads its appendix count as one byte, but it is a VLQCó thể đã có người làm @spuddeh đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày