You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PauseWriterThreshold and ResumeWriterThreshold options of PipeOptions not validated properly #75166
It is possible to pass values of ResumeWriterThreshold and PauseWriterThreshold that causes program to hang. There is a check that disallows ResumeWriterThreshold to be greater than PauseWriterThreshold (code), but it doesn't work in case when ResumeWriterThreshold left to default -1 value and PauseWriterThreshold passed explicitly and less than DefaultResumeWriterThreshold. In this case options contains ResumeWriterThreshold that greater than PauseWriterThreshold and writer resume never happens.
Similar situation come when passed ResumeWriterThreshold equal to 0. In this case this check is not true even if _unconsumedBytes is zero and writer is not resumed. Not sure is it lack of validation of wrong options value or bug in code that should work with zero value.
Reproduction Steps
Here is small program that successfully completes with correct values and hangs forever in cases described above
usingSystem.Buffers;usingSystem.IO.Pipelines;usingSystem.Text;//correct values for immediate backpressure// var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 1, resumeWriterThreshold: 1));//using default resumeWriterThreshold gives incorrect combination of valuesvarpipe=newPipe(newPipeOptions(pauseWriterThreshold:1,resumeWriterThreshold:-1));//with zero resumeWriterThreshold program also hangsvarpipe=newPipe(newPipeOptions(pauseWriterThreshold:1,resumeWriterThreshold:0));varreadTask=Task.Run(async()=>{ReadResultread;do{read=awaitpipe.Reader.ReadAsync();Console.WriteLine($"Read {Encoding.UTF8.GetString(read.Buffer.ToArray())}");pipe.Reader.AdvanceTo(read.Buffer.End);}while(!read.IsCompleted);});varwriteTask=Task.Run(async()=>{awaitpipe.Writer.WriteAsync(Encoding.UTF8.GetBytes("qwerty1"));awaitTask.Delay(100);awaitpipe.Writer.WriteAsync(Encoding.UTF8.GetBytes("qwerty2"));awaitpipe.Writer.CompleteAsync();});awaitTask.WhenAll(readTask,writeTask);
Expected behavior
PipeOptions constructor should throw ArgumentOutOfRangeException for such invalid values
Activity
wtgodbe commentedon Sep 7, 2022
Thanks for the report - we think this is a good candidate for a community contribution, so applying the
help wantedlabelcdbullard commentedon Oct 23, 2022
Hi all,
I have opened a PR that I believe should correct this behavior, please let me know if anything was missed or if any changes might be required.
cdbullard commentedon Nov 7, 2022
Hello,
Just wanted to check in to see if anyone was able to review my PR, let me know if there are any questions. Thanks!