How to deal with sporadic BadStatusLine, CannotSendRequest errors in python WebDriver How to deal with sporadic BadStatusLine, CannotSendRequest errors in python WebDriver jenkins jenkins

How to deal with sporadic BadStatusLine, CannotSendRequest errors in python WebDriver


For a while, I had no repro and no idea what the cause was. I was finally able to repro by running:

import requestsimport jsonwhile True:  requests.post('http://127.0.0.1/hub/session/', data=json.dumps({"url": "http://example.com/login", "sessionId": "ab64574a-4a17-447a-b2e8-5b0f5ed5e923"}))

While this was running, I quit the browser and got a BadStatusLine error! When I tried making that request again, that's when I got the expected "ConnectionError" that you would see from any dead server.

SO, what I suspect happens is that when the browser is sent the kill signal, there is a short window during its shutdown where any response will still be returned but with 0 bytes. That's why you get different types of exceptions for essentially the same problem (browser dies). Turns out we had a cron which was killing our browsers in the background.