google / timesketch

Collaborative forensic timeline analysis
Apache License 2.0
2.61k stars 589 forks source link

urllib3/util/timeout.py", line 150, in _validate_timeout #2648

Open jaegeral opened 1 year ago

jaegeral commented 1 year ago

Describe the bug

Doing an API call on my dev container, I for some reason get

[2023-03-30 08:25:00 +0000] [1778] [ERROR] Error handling request /api/v1/sketches/1/event/tagging/
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/util/timeout.py", line 150, in _validate_timeout
    if value <= 0:
TypeError: '<=' not supported between instances of 'bytes' and 'int'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/opensearchpy/connection/http_urllib3.py", line 240, in perform_request
    response = self.pool.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 687, in urlopen
    timeout_obj = self._get_timeout(timeout)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 330, in _get_timeout
    return Timeout.from_float(timeout)
  File "/usr/lib/python3/dist-packages/urllib3/util/timeout.py", line 179, in from_float
    return Timeout(read=timeout, connect=timeout)
  File "/usr/lib/python3/dist-packages/urllib3/util/timeout.py", line 103, in __init__
    self._connect = self._validate_timeout(connect, "connect")
  File "/usr/lib/python3/dist-packages/urllib3/util/timeout.py", line 158, in _validate_timeout
    raise ValueError(
ValueError: Timeout value connect was b'3', but it must be an int, float or None.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/usr/local/lib/python3.10/dist-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/middleware/profiler.py", line 113, in __call__
    profile.runcall(runapp)
  File "/usr/lib/python3.10/cProfile.py", line 109, in runcall
    return func(*args, **kw)
  File "/usr/local/lib/python3.10/dist-packages/werkzeug/middleware/profiler.py", line 103, in runapp
    app_iter = self._app(
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/flask_restful/__init__.py", line 271, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/flask_restful/__init__.py", line 271, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.10/dist-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/flask/views.py", line 84, in view
    return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/flask_login/utils.py", line 261, in decorated_view
    return func(*args, **kwargs)
  File "/usr/local/src/timesketch/timesketch/api/v1/resources/event.py", line 754, in post
    datastore.flush_queued_events()
  File "/usr/local/src/timesketch/timesketch/lib/datastores/opensearch.py", line 1031, in flush_queued_events
    results = self.client.bulk(
  File "/usr/lib/python3/dist-packages/opensearchpy/client/utils.py", line 178, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
  File "/usr/lib/python3/dist-packages/opensearchpy/client/__init__.py", line 409, in bulk
    return self.transport.perform_request(
  File "/usr/lib/python3/dist-packages/opensearchpy/transport.py", line 406, in perform_request
    raise e
  File "/usr/lib/python3/dist-packages/opensearchpy/transport.py", line 369, in perform_request
    status, headers_response, data = connection.perform_request(
  File "/usr/lib/python3/dist-packages/opensearchpy/connection/http_urllib3.py", line 255, in perform_request
    raise ConnectionError("N/A", str(e), e)
opensearchpy.exceptions.ConnectionError: ConnectionError(Timeout value connect was b'3', but it must be an int, float or None.) caused by: ValueError(Timeout value connect was b'3', but it must be an int, float or None.)
nith2001 commented 1 year ago

DISCLAIMER: Very new to Timesketch (like 2 hours)

I tried to follow the stack trace above and it led me totimesketch/lib/datastores/opensearch.py on Line 1031-1032 where it says timeout=self._request_timeout. When you trace back what self._request_timeout is, that takes you to Line 141-142 where a field called self.DEFAULT_EVENT_IMPORT_TIMEOUT is used. This is defined on Line 109 as

DEFAULT_EVENT_IMPORT_TIMEOUT = "3m"

I know this is such a weak connection 😅, but the 3 in here might related to the b'3' thing that's going on in your stack error trace. Figured I'd just write this down before I forgot it. Kind of a silly conclusion, but who knows. Could you give more information on how you made the API call?