Over a million developers have joined DZone.

The Case of the Hanging Request in the Cache

DZone's Guide to

The Case of the Hanging Request in the Cache

A user of RavenDB reported that all requests were hanging and eventually timed out. We were able to fix the problem... but we still don't know how to reproduce it.

Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

A user just reported that after a short time of using RavenDB, all requests started to hang and eventually timed out. We are talking about making several dozen requests in the space of a minute or so, as a user operating against a web application.

That was a cause of concern, obviously, and something that was very strange. Luckily, the user was able to send us a stripped down version of his application and we were able to reproduce this state locally — on that particular application only. We couldn’t reproduce this anywhere else.

In fact, we fixed the problem and still don’t know how to reproduce it. The underlying issue is that we are making a GET request using HttpClient and specifying HttpCompletionOption.ResponseHeadersRead  in the SendAsync method. Now, the server might return us a 304 response, in which case we’ll use the cached value we have. If we make a few requests like that, all future requests will hang. In order to fix this problem, we need to dispose the response or read the (empty) content of the response.

Now, the crazy thing is that I can probably speculate pretty accurately on why this is going on — we have fixed it — but I can’t reproduce this problem except within the application the user sent us. So, no independent reproduction.

The likely issue is that the HttpClient considers the request open until we read all its content (even if there is none), and that as we make more requests that have the same 304 and therefore there's no access to the content of the request, we have more and more requests that are considered to be open, up to the maximum number of requests that are allowed against the server concurrently. At this point, we are waiting for time-out, and it looks like we are hanging.

All very reasonable and perfectly understandable (if only annoying because if you only need to dispose of it, sometimes is a trap waiting to happen), but I don’t know why we couldn’t reproduce it.

Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.

performance ,cache ,hanging requests ,ravendb ,performance issues

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}