We have encountered this issue on a few different Magento projects. We understand we may not have sufficient information or very clear procedures for reproducing the issue, but as this turned out to be quite annoying and we have no clue about the root cause at all, we still decided to raise this here. And we have seen similar issues on StackOverflow.
Case 1:
Case 2:

It happened (seemingly) randomly, and after restarting the varnish service, the issue would be gone.
I've exact the same issue at some specific category pages. Has anyone find a solution?
I'm experiencing the same issue here, I thought it was the Amasty Extension Layered Navigation, but is still happening without the extension, definitely is something related with Varnish and Magento Core, and clearly this happens on a random way, and there is not a pattern or clue about how to reproduce it.
Does someone have any clue about it? thank you very much in advance.
Apache version: Apache/2.4.6 (CentOS)
Magento: Commerce 2.3.4
Varnish: (varnish-5.2.1 revision 67e562482)

Update:
I have tried disabling the whole varnish, just making a bypass, and the issue still happening. (of course cleared cache before/after)
If you are having the same issue, please could you let us know your current request flow?, I'm pretty sure this is a forwarding/redirect request issue with Magento of course.
Apache Proxy SSL Termination + Varnish = Same Server
Magento Instance = Another Server same setup (Apache)
The current setup is, Client -> CloudFlare (free) -> Apache (Proxy SSL termination) -> Varnish -> Magento
Thanks,
I have found the cause and the solution. The cause is that when Varnish is cleared and a user comes to a filtered page first, the JSON is cached. I have excluded this for Varnish and this solved the problem.
I have found the cause and the solution. The cause is that when Varnish is cleared and a user comes to a filtered page first, the JSON is cached. I have excluded this for Varnish and this solved the problem.
@jbclaudio
O-M-G finally someone came up with a solution!
That's some amazing findings there mate.
Do you mind sharing the VCL rules you have added?
I have found the cause and the solution. The cause is that when Varnish is cleared and a user comes to a filtered page first, the JSON is cached. I have excluded this for Varnish and this solved the problem.
Wow, great job! Would you please share with us your VCL rules?
I have found the cause and the solution. The cause is that when Varnish is cleared and a user comes to a filtered page first, the JSON is cached. I have excluded this for Varnish and this solved the problem.
@jbclaudio That sounds great, but I'm curious because I've tried disabling Varnish and this still happening, are you completely sure is fixed? Did you were able to reproduce the issue to verify if the fix is real? I would like to think that you are our savior in this very rare issue :P, and as our bug-mates said, please could you show us that portion of the VCL file?, thanks
I have found the cause and the solution. The cause is that when Varnish is cleared and a user comes to a filtered page first, the JSON is cached. I have excluded this for Varnish and this solved the problem.
On second thought, I could not figure out the relationship between the filtered page and the unfiltered page.
Aren't those filtered pages standalone cache entries in Varnish?
And I tried to follow your findings, but still could not find a way to 100% reproduce the issue as well.
Could you please also advise how you could do that?
I've added this to the .vcl file:
if (req.url ~ "shopbyAjax") {
return (pass);
}
This project uses the Amasty Shopby module. This added the parameter to the filter pages, which I could use. You may be able to use another parameter that Magento itself adds.
After this has been added to the .vcl file, the problem no longer occurs.
I just encountered this and was able to quickly resolve it, so I thought I would share my solution here: I just reran the catalog_product_category and catalog_category_product indexers
Most helpful comment
I have found the cause and the solution. The cause is that when Varnish is cleared and a user comes to a filtered page first, the JSON is cached. I have excluded this for Varnish and this solved the problem.