selenium-wire icon indicating copy to clipboard operation
selenium-wire copied to clipboard

selenium wire errors with multithreading

Open jordibonastrem opened this issue 3 years ago • 4 comments

Hi, selenium wire is working fine with one thread, but when i try to run multiple threads this error is shown

Traceback (most recent call last):
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\server.py", line 113, in handle
    root_layer()
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\modes\http_proxy.py", line 23, in __call__
    layer()
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\tls.py", line 
285, in __call__
    layer()
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\http1.py", line 100, in __call__
    layer()
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\http.py", line 206, in __call__
    if not self._process_flow(flow):
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\http.py", line 288, in _process_flow
    return self.handle_upstream_connect(f)
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\http.py", line 251, in handle_upstream_connect
    self.send_response(f.response)
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\http.py", line 54, in send_response
    self.send_response_body(response, [response.data.content])
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\server\protocol\http1.py", line 72, in send_response_body
    self.client_conn.wfile.write(chunk)
  File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\seleniumwire\thirdparty\mitmproxy\net\tcp.py", line 98, in write    raise exceptions.TcpDisconnect(str(e))
seleniumwire.thirdparty.mitmproxy.exceptions.TcpDisconnect: [WinError 10053] Se ha anulado una conexión establecida por el software en 
su equipo host

Im using ThreadPoolExecutor to generate threads

with concurrent.futures.ThreadPoolExecutor() as executor:
                    for taskid in range(int(CREDENTIALS.TASK_NUM)):
                        
                        self.choseProxie(taskid)
                        executor.submit(self.startTask,taskid)

What can i do to solve it ??

jordibonastrem avatar Aug 27 '21 21:08 jordibonastrem

Thanks for raising this.

How many threads are you using when you see the problem? Are you using any upstream proxy? If so, does the error still happen if you omit the proxy and go direct?

wkeeling avatar Aug 27 '21 21:08 wkeeling

Im using 10 threads, if i dont use proxies error doesn't show. btw, how can i deactivate seleniumwire error logs? so i dont get this exception in console:

seleniumwire.thirdparty.mitmproxy.exceptions.TcpDisconnect: [WinError 10053] Se ha anulado una conexión establecida por el software en 
su equipo host

jordibonastrem avatar Aug 27 '21 21:08 jordibonastrem

Thanks. I'll need to try and reproduce the issue on Windows. The error message may be escaping the standard logging mechanism which is why you're not able to suppress it. That's been raised as an issue before, so I'll see if I can figure out what's going on.

wkeeling avatar Aug 27 '21 21:08 wkeeling

This looks as though it's caused by a bug introduced in version 4.3.3. As a short term fix you may be able to resolve the problem by downgrading:

pip install selenium-wire==4.3.2

Related to #389

wkeeling avatar Sep 07 '21 18:09 wkeeling