Started receiving messages about potential deadlock
Starting today I'm suddenly getting lots of rather lengthy messages in the "Observability" log of my worker:
A stalled HTTP response was canceled to prevent deadlock. This can happen when a Worker calls fetch() or cache.match() several times without reading the bodies of the returned Response objects. There is a limit on the number of concurrent HTTP requests that can be in-flight at one time. Normally, additional requests made beyond that limit are delayed until previous responses complete. However, because the Worker did not read the responses, they would never complete. Therefore, to prevent deadlock, the oldest response was canceled. To avoid this warning, make sure to either read the body of every HTTP Response or call response.body.cancel() to cancel a response that you don't plan to read from.Where are these coming from? I tried to narrow down to a logging statement in my code. But I think it's not coming from any of them. Nor can I figure out what would be triggering these. I tried to reproduce locally in my dev environment using the same parameters as the original call. But that wouldn't cause anything. Is there any way to find out where (in my code) these are coming from?
1 Reply
Hmm... sometimes I would get multiple of these warnings for a single request? I'm not doing parallel sub-requests, AFAIK.
Ok, figured it out. There indeed was one case where I'd do multiple
fetchin parallel, and which did not read the body, only headers (it's a HEAD request). I guess the message I've started receiving is something that was introduced recently. Didn't know I had to read the body for a HEAD request...