C
C#14mo ago
Anton

❔ System.IO.Pipelines cannot complete the reader

Hey. I'm having reader.CompleteAsync throw because it tries to return an empty buffer to the array pool. All of the reading goes successfully, but when I try to CompleteAsync the reader, it ends up in that code with an invalid state for one of the segments, apparently Does anyone have any idea what could be up? Approximate code is here (it doesn't contain the data structures, just shows the most important functions). https://paste.mod.gg/wchbuamcrxfn/0
BlazeBin - wchbuamcrxfn
A tool for sharing your source code with the world!
No description
11 Replies
Anton
AntonOP14mo ago
@Wraith2 Sorry for the ping, take a look pls if you don't mind. You might be familiar with the issue
Wraith2
Wraith214mo ago
is this your code or code from inside pipelines?
Anton
AntonOP14mo ago
On the image the code is from the library My code is by the link The image might be misleading, but the stack trace shows me an ArgumentNullException in the array pool implementation, which originated in this funciton
Wraith2
Wraith214mo ago
i'm using https://github.com/mgravell/Pipelines.Sockets.Unofficial which wraps a lot of direct access stuff for me
GitHub
GitHub - mgravell/Pipelines.Sockets.Unofficial: .NET managed socket...
.NET managed sockets wrapper using the new "Pipelines" API - GitHub - mgravell/Pipelines.Sockets.Unofficial: .NET managed sockets wrapper using the new "Pipelines" API
Wraith2
Wraith214mo ago
but pipelines is an official and supported api so if you can repro the problem open an issue and someone should look
Anton
AntonOP14mo ago
Yeah I don't know if I will be able to reproduce this. It just happened to have worked just now. 2 times in a row. We'll see if it comes up again Thanks for the link And now it broke again I don't think this can be a race condition on my side of things though. At a glance, I seem to be awaiting everything diligently. This is really strange @Wraith2 the error seems to manifest itself only when I put a breakpoint in the code that does the parsing. If I just run it past, it works without issue Yep, just checked it. Works without a breakpoint, doesn't work with one It's got to be a race condition. It does sometimes trigger without a breakpoint.
Wraith2
Wraith214mo ago
in which case definately see if you can isolate a reproduction and open an issue for it, race conditions are hell in production.
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Anton
AntonOP14mo ago
@Wraith2 It was an issue from my side after all. Basically, AdvanceTo silently trusts the input sequence positions, it doesn't validate if they're even part of one of the buffers. Having read some of the issues on github on that, it seems like checking if an arbitrary position is in the sequence is expensive, which is why they just don't do it. I did spend a good 8 hours on debugging this though. If only there way a feature in C# to enable conditions in compiled library code without incurring a runtime cost (aka without runtime bool checks), it could be really useful here.
Wraith2
Wraith214mo ago
Hmm, feels like a pit of failure it'd be good to have some sort of warning about somewhere. but good that you got it sorted.
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server