Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duffy client should handle HTTP errors gracefully #525

Open
mrc0mmand opened this issue Aug 5, 2022 · 1 comment
Open

Duffy client should handle HTTP errors gracefully #525

mrc0mmand opened this issue Aug 5, 2022 · 1 comment

Comments

@mrc0mmand
Copy link

This is somewhat related to #523, as it causes this issue to pop up quite often, but the duffy client should handle non-successful HTTP codes instead of throwing exceptions around, to make it consistent with the rest of the DuffyAPIErrorModel:

2022-08-05 09:30:42,932 [agent-control/allocate_node] INFO: Attempting to allocate a node from pool metal-seamicro-large-centos-8s-x86_64
2022-08-05 09:30:43,446 [agent-control/main] ERROR: Execution failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/duffy/client/main.py", line 101, in _query_method
    return DuffyAPIErrorModel(error=response.json())
  File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 743, in json
    return jsonlib.loads(self.text, **kwargs)
  File "/usr/lib64/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./agent-control.py", line 315, in main
    node = ac.allocate_node(args.pool)
  File "./agent-control.py", line 59, in allocate_node
    result = self._client.request_session([payload])
  File "/usr/local/lib/python3.8/site-packages/duffy/client/main.py", line 123, in request_session
    return self._query_method(
  File "/usr/local/lib/python3.8/site-packages/duffy/client/main.py", line 103, in _query_method
    response.raise_for_status()
  File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 736, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Server error '500 Internal Server Error' for url 'https://duffy.ci.centos.org/api/v1/sessions'
For more information check: https://httpstatuses.com/500

Ideally it should fill the DuffyAPIErrorModel with the HTTP status error details and pass it down as usual, to make error handling consistent.

@mrc0mmand mrc0mmand changed the title Duffy should handle HTTP errors gracefully Duffy client should handle HTTP errors gracefully Aug 5, 2022
@mrc0mmand
Copy link
Author

This should maybe also get handled somewhat more gracefully:

2022-08-09 05:29:53,328 [agent-control/allocate_node] INFO: Attempting to allocate a node from pool virt-one-medium-centos-8s-ppc64le
2022-08-09 05:29:58,349 [agent-control/main] ERROR: Execution failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
    yield
  File "/usr/local/lib/python3.8/site-packages/httpcore/backends/sync.py", line 26, in read
    return self._sock.recv(max_bytes)
  File "/usr/lib64/python3.8/ssl.py", line 1226, in recv
    return self.read(buflen)
  File "/usr/lib64/python3.8/ssl.py", line 1101, in read
    return self._sslobj.read(len)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 218, in handle_request
    resp = self._pool.handle_request(req)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 253, in handle_request
    raise exc
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 237, in handle_request
    response = connection.handle_request(request)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 90, in handle_request
    return self._connection.handle_request(request)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http11.py", line 105, in handle_request
    raise exc
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http11.py", line 84, in handle_request
    ) = self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http11.py", line 148, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http11.py", line 177, in _receive_event
    data = self._network_stream.read(
  File "/usr/local/lib/python3.8/site-packages/httpcore/backends/sync.py", line 26, in read
    return self._sock.recv(max_bytes)
  File "/usr/lib64/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc)
httpcore.ReadTimeout: The read operation timed out

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

Traceback (most recent call last):
  File "./agent-control.py", line 330, in main
    ac.allocate_node(args.pool)
  File "./agent-control.py", line 69, in allocate_node
    result = self._client.request_session([payload])
  File "/usr/local/lib/python3.8/site-packages/duffy/client/main.py", line 123, in request_session
    return self._query_method(
  File "/usr/local/lib/python3.8/site-packages/duffy/client/main.py", line 94, in _query_method
    response = client_method(url=url, **add_kwargs)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1130, in post
    return self.request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 815, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 902, in send
    response = self._send_handling_auth(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 930, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 967, in _send_handling_redirects
    response = self._send_single_request(request)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1003, in _send_single_request
    response = transport.handle_request(request)
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 218, in handle_request
    resp = self._pool.handle_request(req)
  File "/usr/lib64/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: The read operation timed out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant