Intermittent XMLHttpRequest error
Hi,
I get random intermittent ClientException stating XMLHttpRequest error with around 1 - 2% of requests made. The issue is only affecting mobile users on web as far as I can see with some user agents example below
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36
Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Mobile/15E148 Safari/604.1
Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Mobile/15E148 Safari/604.1
Mozilla/5.0 (Linux; U; Android 11; fr-fr; Redmi Note 10 Build/RKQ1.201022.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/112.0.5615.136 Mobile Safari/537.36 XiaoMi/MiuiBrowser/14.9.1-gn
Issue could affect any request made, there's no specific request although I never seen it affecting the very first request made on the application (could be luck though)
I've been troubleshooting this issue for almost 6 months now without being able to find a solution
It's not CORS nor SSL certificates related, both are properly setup and failure rate would be higher if they were the issue to pinpoint anyway.
I'm running my server behind an API Gateway and catching those issues on production using Sentry. From what I could see, corresponding request failure raised from Sentry (on the client side) just never made it to the server, there's absolutely no access log on my API gateway when the error is raised while every other requests are properly logged (even failures). So I suspect the issue reside within the frontend part
Those could be suddden loss of internet from the mobile device but I would not receive the error at the time it occurs in my error tracking tool nor it would just fail in between very close queries. I also witnessed the bug in person with a very good internet connection, I just couldn't have the inspector to run at that time.
I tried to reproduce the issue with no luck with the inspector open (Sending more than 5000 queries using the application on web mobile and having chrome inspector opened) so I never caught the console error
At this point, I just don't know what else could be done, I feel like not having more information on the issue is very frustrating since we're searching a needle in a haystack
It is unlikely that this is an error with the implementation of BrowserClient since it just wraps the JavaScript XMLHttpRequest.
You could try to use package:fetch_client to see if that helps.
Please reopen if package:fetch_client doesn't solve the problem.
Hi @brianquinlan, I dig it up very deeply and the issue is related with HTTP 1.1 protocol and keep-alive race condition (socket timeout from the server at the very same time client wants to make a new request)
I had to switch to native fetch implementation which now works as intended
I tried to use non persistent flag on each requests + disable keep alive on server with no luck too. Please see the attached wireshark log to get a better view of non persistent issue
Here you can see that the client depite receiving a FIN+ACK and sending an ACK decide to make a new request on the same TCP connexion more than 10 seconds later.