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

后端 未结 1 970
刺人心
刺人心 2021-01-18 15:40

Since we started running selenium UI tests in jenkins, we noticed a small but annoying frequency of errors during tests. We get BadStatusLine and CannotSendRequest errors on

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 16:10

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

    import requests
    import json
    
    while 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.

    0 讨论(0)
提交回复
热议问题