-
Notifications
You must be signed in to change notification settings - Fork 2.1k
PagedCharBuffer, Append(string value), never ending loop #5347
Comments
Do you have a sample page/app that is broken? |
I'm not able to provide the application as it involves a database and other stuff (images, etc.). I believe the problem arises when the web page generated code grows and contains >50k of JSON (serialized model). I recall that when the never ending loop started we had about 50 arrays (pages) of 1k each. However, the code In that loop is error prone as the size of the resulting page is not fixed. |
@dougbu can you take a look? |
@Eilon what's probably happening is a @psicus78's suggestion should work fine as long as we apply it to the Repro scenario involves writing at least 50k characters to a |
Clearing |
Great! I hope this will be shipped by 1.1.0 because it's a big problem for my application. |
@psicus78 is this broken for you in 1.0.0-1.0.1? Or are you using 1.1.0? @Eilon If this is broken in LTS this seems like a good patch candidate. |
@rynowak I'm using dotnet.myget.org/aspnetcore 1.1.0-alpha-* packages because I need signalR which is still alpha. |
No obvious bounds checking issues related to It's good I looked because our current code also uses incorrect bounds in |
Fixed missing word in previous comment. |
Spoke to folks in person. It appears that this cannot repro on 1.0.x, so we'll just fix in 1.1.0. |
- #5347 - inconsistent bounds checking caused problems after `ArrayPool<char>` fell back to `new char[2048]` - would fail a `Debug` assertion in Debug builds and loop endlessly in Release builds - change to `CacheTagHelper+CharBufferHtmlContent` is for correctness only - always uses a `CharArrayBufferSource` and that returns arrays of the exact size requested
- #5347 - inconsistent bounds checking caused problems after `ArrayPool<char>` fell back to `new char[2048]` - would fail a `Debug` assertion in Debug builds and loop endlessly in Release builds - change to `CacheTagHelper+CharBufferHtmlContent` is for correctness only - always uses a `CharArrayBufferSource` and that returns arrays of the exact size requested
- #5347 - inconsistent bounds checking caused problems after `ArrayPool<char>` fell back to `new char[2048]` - would fail a `Debug` assertion in Debug builds and loop endlessly in Release builds - change to `CacheTagHelper+CharBufferHtmlContent` is for correctness only - always uses a `CharArrayBufferSource` and that returns arrays of the exact size requested
In file PagedCharBuffer.cs, method
public void Append(string value)
, the loopwhile (count > 0)
at line 56 doed not exit in some scenarios. As a result, the web application hangs.The problem is that GetCurrentPage and NewPage calls within the loop make use of ArrayPool.RentUse (
public abstract T[] Rent(int minimumLength
) which takes one parameter, which is the minimumLength. Sometimes the actual length of the returned array is greater than requested one (1024 corresponding to PageSize const). As soon as this happens (apparently when Append argument is a quite long string) any further invokation of GetCurrentPage fails to get new pages.In fact,
if (CurrentPage == null || _charIndex == PageSize
returns false as _charIndex is now set to a different value than the expected PageSize (2048 whenever I experienced the bug).I solved the bug by changing line 59 like this
var copyLength = Math.Min(count, PageSize - _charIndex);
The text was updated successfully, but these errors were encountered: