gpt4free icon indicating copy to clipboard operation
gpt4free copied to clipboard

Unknown error: cannot connect to chrome at 127.0.0.1:58186

Open iG8R opened this issue 1 year ago • 10 comments
trafficstars

Every now and then, when the size of the %localappdata%\g4f\g4f becomes about 2.7GB, the following error brings up with any provider that needs authorization. The only thing that helps is the removal of %localappdata%\g4f\g4f. Is there any way to fix this issue without such a harsh method?

Using Gemini provider and gpt-4 model
Open browser with config dir: C:\Users\iG8R\AppData\Local\g4f\g4f
ERROR:root:Message: unknown error: cannot connect to chrome at 127.0.0.1:58186
from chrome not reachable
Stacktrace:
        GetHandleVerifier [0x00E71673+52979]
        (No symbol) [0x00DF7961]
        (No symbol) [0x00CDDC00]
        (No symbol) [0x00CD1D83]
        (No symbol) [0x00D08CE9]
        (No symbol) [0x00D013F5]
        (No symbol) [0x00D01227]
        (No symbol) [0x00D3D2B1]
        (No symbol) [0x00D3CE5A]
        (No symbol) [0x00D34286]
        (No symbol) [0x00D0C063]
        (No symbol) [0x00D0CECD]
        GetHandleVerifier [0x01188D83+3294723]
        GetHandleVerifier [0x011C6CC2+3548482]
        GetHandleVerifier [0x011C1C9C+3527964]
        GetHandleVerifier [0x00F0870E+671630]
        (No symbol) [0x00E01EB4]
        (No symbol) [0x00DFD808]
        (No symbol) [0x00DFD92D]
        (No symbol) [0x00DEF7E0]
        BaseThreadInitThunk [0x76BF00F9+25]
        RtlGetAppContainerNamedObjectPath [0x77B17BBE+286]
        RtlGetAppContainerNamedObjectPath [0x77B17B8E+238]
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\gui\server\backend.py", line 185, in _create_response_stream
    for chunk in ChatCompletion.create(**kwargs):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\base_provider.py", line 201, in create_completion
    yield loop.run_until_complete(gen.__anext__())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\Gemini.py", line 71, in create_async_generator
    driver = get_browser(proxy=proxy)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\webdriver.py", line 64, in get_browser
    return Chrome(
           ^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 466, in __init__
    super(Chrome, self).__init__(
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 61, in __init__
    super().__init__(command_executor=executor, options=options)
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 209, in __init__
    self.start_session(capabilities)
  File "c:\gpt4free\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 724, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 348, in execute
    self.error_handler.check_response(response)
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:58186
from chrome not reachable
Stacktrace:
        GetHandleVerifier [0x00E71673+52979]
        (No symbol) [0x00DF7961]
        (No symbol) [0x00CDDC00]
        (No symbol) [0x00CD1D83]
        (No symbol) [0x00D08CE9]
        (No symbol) [0x00D013F5]
        (No symbol) [0x00D01227]
        (No symbol) [0x00D3D2B1]
        (No symbol) [0x00D3CE5A]
        (No symbol) [0x00D34286]
        (No symbol) [0x00D0C063]
        (No symbol) [0x00D0CECD]
        GetHandleVerifier [0x01188D83+3294723]
        GetHandleVerifier [0x011C6CC2+3548482]
        GetHandleVerifier [0x011C1C9C+3527964]
        GetHandleVerifier [0x00F0870E+671630]
        (No symbol) [0x00E01EB4]
        (No symbol) [0x00DFD808]
        (No symbol) [0x00DFD92D]
        (No symbol) [0x00DEF7E0]
        BaseThreadInitThunk [0x76BF00F9+25]
        RtlGetAppContainerNamedObjectPath [0x77B17BBE+286]
        RtlGetAppContainerNamedObjectPath [0x77B17B8E+238]

127.0.0.1 - - [09/Feb/2024 16:49:39] "POST /backend-api/v2/conversation HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [09/Feb/2024 16:49:39] "POST /backend-api/v2/conversation HTTP/1.1" 200 -
ERROR:root:('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\http\client.py", line 1411, in getresponse
    response.begin()
  File "C:\Python312\Lib\http\client.py", line 324, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\http\client.py", line 285, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\socket.py", line 707, in readinto
    return self._sock.recv_into(b)
           ^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\gui\server\backend.py", line 185, in _create_response_stream
    for chunk in ChatCompletion.create(**kwargs):
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\base_provider.py", line 201, in create_completion
    yield loop.run_until_complete(gen.__anext__())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\Provider\needs_auth\Gemini.py", line 71, in create_async_generator
    driver = get_browser(proxy=proxy)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\g4f\webdriver.py", line 64, in get_browser
    return Chrome(
           ^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 466, in __init__
    super(Chrome, self).__init__(
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 61, in __init__
    super().__init__(command_executor=executor, options=options)
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 209, in __init__
    self.start_session(capabilities)
  File "c:\gpt4free\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 724, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
    response = self.command_executor.execute(driver_command, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 300, in execute
    return self._request(command_info[0], url, body=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 321, in _request
    response = self._conn.request(method, url, body=body, headers=headers)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\_request_methods.py", line 118, in request
    return self.request_encode_body(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\_request_methods.py", line 217, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\poolmanager.py", line 444, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\util\retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\util\util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "c:\gpt4free\venv\Lib\site-packages\urllib3\connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\http\client.py", line 1411, in getresponse
    response.begin()
  File "C:\Python312\Lib\http\client.py", line 324, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\http\client.py", line 285, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\socket.py", line 707, in readinto
    return self._sock.recv_into(b)
           ^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
127.0.0.1 - - [09/Feb/2024 16:49:48] "POST /backend-api/v2/conversation HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [09/Feb/2024 16:49:48] "POST /backend-api/v2/conversation HTTP/1.1" 200 -

iG8R avatar Feb 09 '24 15:02 iG8R

I have same issue. It is a problem with selenium. By default selenium deletes the dir on closing. I don't know a alternative.

hlohaus avatar Feb 09 '24 15:02 hlohaus

Oh, I got it. Maybe someone on the board has been able to resolve this issue and could share with us?

iG8R avatar Feb 09 '24 15:02 iG8R

I set patcher_force_close=True in: g4f/webdriver.py in the last release.

Can you verify that it works? I had since yesterday no problems.

hlohaus avatar Feb 10 '24 12:02 hlohaus

I set patcher_force_close=True in: g4f/webdriver.py

Can you verify that it works? I had since yesterday no problems.

hlohaus avatar Feb 10 '24 12:02 hlohaus

Thanks a lot for your work! Since yesterday and until now, I have not encountered this issue, but previously, as I mentioned above, this situation occurred off and on, so it needs time to make sure it is fixed.

iG8R avatar Feb 10 '24 12:02 iG8R

You can delete the C:\Users\iG8R\AppData\Local\g4f\g4f and retry ~

lotusnowshen avatar Feb 12 '24 15:02 lotusnowshen

@lotusnowshen

You can delete the C:\Users\iG8R\AppData\Local\g4f\g4f and retry ~

That is exactly what I do and wrote about it in my first message:

The only thing that helps is the removal of %localappdata%\g4f\g4f.

That is why there was a question: Is there any way to fix this issue without such a harsh method?

iG8R avatar Feb 12 '24 16:02 iG8R

I think the browser aren't closed. The PID files are in this dir and they and the dir must be deleted. Are using the original user dir, i have the same issue

hlohaus avatar Feb 13 '24 07:02 hlohaus

On build 0.2.1.3, I no longer encounter this problem so far, but I still wonder which PID files need to be deleted?

iG8R avatar Feb 13 '24 11:02 iG8R

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] avatar Feb 21 '24 00:02 github-actions[bot]