Issuing a Cancel on a CancellationToken while reading xe live target leads to blocking in a server packet
Maintainer thường phản hồi trong vòng 2 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
- 62/100
Hướng nghiên cứu
Start with the provided reproducer and the stack-trace entry points XELiveEventStreamer.ReadEventStream and SqlDataReader.TryCloseInternal; the issue does not name repository files or tests. Trace what happens when the cancellation token is canceled inside the event handler, then verify that reading exits after 10 events and the final count is printed.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
I am not certain whether this a bug in the driver or in xelite (or maybe I'm doing something wrong that isn't obvious). The issue is that using the XELiveEventStreamer class in the XELite nuget package from Microsoft to read the live target can cause an app deadlock if the calling code issues a Cancel call on the CancellationToken it passes in to the streamer while handling an incoming XEvent.
I've tried both 6.1.8 and 7.1.1 of SqlClient and see the same issue.
Exception message: None
Stack trace:
[Managed to Native Transition] Non-user code. Annotated Frame
Microsoft.Data.SqlClient.dll!Interop.Windows.Sni.SniNativeMethods.SniReadSyncOverAsync(Microsoft.Data.SqlClient.SNIHandle pConn, ref nint ppNewPacket, int timeout) Line 105 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SniNativeWrapper.SniReadSyncOverAsync(Microsoft.Data.SqlClient.SNIHandle pConn, ref nint ppNewPacket, int timeout) Line 437 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.TdsParserStateObjectNative.ReadSyncOverAsync(int timeoutRemaining, out uint error) Line 325 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() Line 2690 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() Line 2645 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() Line 1291 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.TdsParserStateObject.TryReadByte(out byte value) Line 1531 C# Symbols loaded.
> Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.TdsParser.TryRun(Microsoft.Data.SqlClient.RunBehavior runBehavior, Microsoft.Data.SqlClient.SqlCommand cmdHandler, Microsoft.Data.SqlClient.SqlDataReader dataStream, Microsoft.Data.SqlClient.BulkCopySimpleResultSet bulkCopyHandler, Microsoft.Data.SqlClient.TdsParserStateObject stateObj, out bool dataReady) Line 2044 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlDataReader.TryCloseInternal(bool closeReader) Line 1083 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlDataReader.Close() Line 1009 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlDataReader.Dispose(bool disposing) Line 924 C# Symbols loaded.
Microsoft.SqlServer.XEvent.XELite.dll!Microsoft.SqlServer.XEvent.XELite.XELiveEventStreamer.ReadEventStream(Microsoft.SqlServer.XEvent.XELite.HandleMetadata xeMetdataHandler, Microsoft.SqlServer.XEvent.XELite.HandleXEvent xeEventHandler, System.Threading.CancellationToken cancellationToken) Line 63 C# Symbols loaded.
[Resuming Async Method] Annotated Frame
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.SqlServer.XEvent.XELite.XELiveEventStreamer.<ReadEventStream>d__5>.ExecutionContextCallback(object s) Line 292 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 179 C# Symbols loaded.
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.SqlServer.XEvent.XELite.XELiveEventStreamer.<ReadEventStream>d__5>.MoveNext(System.Threading.Thread threadPoolThread) Line 366 C# Symbols loaded.
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.SqlServer.XEvent.XELite.XELiveEventStreamer.<ReadEventStream>d__5>.MoveNext() Line 350 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) Line 795 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3474 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result) Line 385 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.Tasks.TaskCompletionSource<bool>.TrySetResult(bool result) Line 218 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlDataReader.CompleteAsyncCall<bool>(System.Threading.Tasks.Task<bool> task, Microsoft.Data.SqlClient.SqlDataReader.SqlDataReaderBaseAsyncCallContext<bool> context) Line 6074 C# Symbols loaded.
Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlDataReader.SqlDataReaderBaseAsyncCallContext<bool>.CompleteAsyncCallCallback(System.Threading.Tasks.Task<bool> task, object state) Line 5773 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 264 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Line 2346 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 1051 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() Line 118 C# Symbols loaded.
System.Private.CoreLib.dll!System.Threading.Thread.StartCallback() Line 109 C# Symbols loaded.
[Async Call Stack] Annotated Frame
[Async] xelitebug.dll!Program.<Main>$(string[] args) Line 6 C# Symbols loaded.
To reproduce
using Microsoft.SqlServer.XEvent.XELite;
var reader = new XELiveEventStreamer("Data Source=.;user id=sa;password=<redacted>;trustservercertificate=true", "QuickSessionStandard");
var eventCount = 0;
var cts = new CancellationTokenSource();
await reader.ReadEventStream(xevent =>
{
eventCount++;
Console.WriteLine($"Event received: {xevent.Name} {eventCount}");
if (eventCount >= 10)
{
cts.Cancel();
Console.WriteLine($"Cancelled");
// return Task.FromCancelled(cts.Token); doesn't change the behavior if I add it here
}
return Task.CompletedTask;
}, cts.Token).ConfigureAwait(false);
Console.WriteLine($"Total events received: {eventCount}"); // this line never prints, app doesn't exit
Expected behavior
The app should exit after 10 events are received.
Further technical details
Microsoft.Data.SqlClient version: 7.1.1
.NET target: net10
SQL Server version: SQL Server 2025
Operating system: Ubuntu WSL
Additional context
Add any other context about the problem here.
- Ngôn ngữ chính
- C#
- Star
- 1k
- Fork
- 352
- Merge trung bình
- 4 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 86
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- 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 dotnet/SqlClient
-
Sync ExecuteReader on an STA thread deadlocks against a StateChange handler that marshals to the UI thread (OpenAsyncRetry path)Có thể làm lại được @mdaigle đã nhận 43 ngày trước và không có pull request nào đang mở. Đang mởExternal :link:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
dotnet/SqlClient#4534 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Tests | Additional test casesĐang mởArea\Tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
dotnet/SqlClient#4377 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 54/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Approval Needed Code Health :pill: Common Project 🚮 Design Review Needed Up-for-Grabs :raised_hands:
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
dotnet/SqlClient#4940 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Code Health :pill: Up-for-Grabs :raised_hands:
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
dotnet/SqlClient#4937 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của dotnet/SqlClient
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug elsa 3 prio low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
elsa-workflows/elsa-core#9154 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NethermindEth/nethermind#15452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
kind:ux size:S
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
elsa-workflows/elsa-foundation#3563 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
请让 FPS 叠加层的字号大小可单独设置Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày