plasma-umass / cwhy

"See why!" Explains and suggests fixes for compile-time errors for C, C++, C#, Go, Java, LaTeX, PHP, Python, Ruby, Rust, and TypeScript
Apache License 2.0
272 stars 6 forks source link

SSL/HTTP error #10

Closed ProExpertProg closed 1 year ago

ProExpertProg commented 1 year ago

Getting this sequence of errors when running cwhy, and I was curious if you've experienced that:

Traceback (most recent call last):
  File "/home/luka/.local/lib/python3.10/site-packages/anyio/streams/tls.py", line 130, in _call_sslobject_method
    result = func(*args)
  File "/usr/lib/python3.10/ssl.py", line 917, in read
    v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2548)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 34, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/home/luka/.local/lib/python3.10/site-packages/anyio/streams/tls.py", line 195, in receive
    data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
  File "/home/luka/.local/lib/python3.10/site-packages/anyio/streams/tls.py", line 137, in _call_sslobject_method
    data = await self.transport_stream.receive()
  File "/home/luka/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1265, in receive
    await self._protocol.read_event.wait()
  File "/usr/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 32, in read
    with anyio.fail_after(timeout):
  File "/home/luka/.local/lib/python3.10/site-packages/anyio/_core/_tasks.py", line 118, in __exit__
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 116, in handle_async_request
    raise exc
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 95, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 159, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_async/http11.py", line 195, in _receive_event
    data = await self._network_stream.read(
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 31, in read
    with map_exceptions(exc_map):
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/luka/.local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ReadTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/luka/.local/lib/python3.10/site-packages/cwhy/cwhy.py", line 133, in complete
    completion = await openai_async.chat_complete(openai.api_key, timeout=30, payload={'model': 'gpt-3.5-turbo', 'messages': [{'role': 'user', 'content': user_prompt}]})
  File "/home/luka/.local/lib/python3.10/site-packages/openai_async/openai_async.py", line 13, in send_to_openai
    return await client.post(
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_client.py", line 1845, in post
    return await self.request(
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_client.py", line 1617, in send
    response = await self._send_handling_auth(
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_client.py", line 1719, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/luka/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/luka/.local/bin/cwhy", line 8, in <module>
    sys.exit(main())
  File "/home/luka/.local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/luka/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/luka/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/luka/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/luka/.local/lib/python3.10/site-packages/cwhy/__main__.py", line 11, in main
    text = asyncio.run(cwhy.complete(cwhy.cwhy_prompt(fix)))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/luka/.local/lib/python3.10/site-packages/cwhy/cwhy.py", line 136, in complete
    except (openai.error.AuthenticationError, httpx.LocalProtocolError, KeyError):
NameError: name 'httpx' is not defined
nicovank commented 1 year ago

I think this was fixed in 546d85f89734e404dc19298292fe2c144b68b926, I'm not sure whether this is part of the current PyPI release. Is OPENAI_API_KEY defined?

@emeryberger Maybe we should issue a new release?

ProExpertProg commented 1 year ago

Yeah, if I run env:

$ env
SHELL=/bin/bash
NVM_INC=/home/luka/.nvm/versions/node/v16.13.2/include/node
WSL2_GUI_APPS_ENABLED=1
WSL_DISTRO_NAME=Ubuntu-20.04
OPENAI_API_KEY=sk-...
nicovank commented 1 year ago

I am able to reproduce this downloading cwhy from PyPI and manually lowering the timeout to force a timeout error.

I am assuming it hangs for a bit (30 seconds) before failing from the httpx.ReadTimeout? I have also increased the timeout in 22ce96191b405b4e2467e47f8a7d0f0aaa22fed7. We maybe should make it a CLI option. Could you by any chance try with the current main instead of the PyPI version and see if this still happens?

[~] git clone https://github.com/plasma-umass/cwhy.git
[cwhy] pip install .
ProExpertProg commented 1 year ago

Yeah, with a simple message, it does not fail, it's the longer error message that likely takes longer to process and timeout. I'll try with the longer timeout

nicovank commented 1 year ago

Just made the timeout a CLI option in 89fca5c48ea884b4612841b558c0a5d4477c621d and improved the error message in case of timeout in c3a27b6c08a30d7fec310f1d9e28d5f5920ac069.

ProExpertProg commented 1 year ago

Thanks for the quick turnaround!

ProExpertProg commented 1 year ago

(and for what it's worth, it correctly hypothesized that there is an issue with the standard library installation - I was using something from std::ranges that hasn't been implemented in the compiler version I'm using. I am quite impressed!)

emeryberger commented 1 year ago

Thanks - that's great to hear!