Couchbase lib update from 2.2.6 to 2.5.12 throwing: **ValueError: filedescriptor out of range in select()**?

We migrated our service from 2.2.6. to 2.5.12. After this, on load testing we are getting this error:

builtins.ValueError: filedescriptor out of range in select()
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/ddtrace/contrib/flask/patch.py", line 472, in _traced_request
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.6/dist-packages/ddtrace/contrib/flask/wrappers.py", line 25, in trace_func
    return wrapped(*args, **kwargs)
  File "./rest_api/include.py", line 865, in _wrapper
    ret = func(reqData)
  File "./rest_api/exportApi.py", line 677, in wrapper
    locale=locale,
  File "./rest_api/exportApi.py", line 433, in wrapper
    s3file.write(buf.getvalue())
  File "/usr/local/lib/python3.6/dist-packages/smart_open/s3.py", line 538, in __exit__
    self.close()
  File "/usr/local/lib/python3.6/dist-packages/smart_open/s3.py", line 452, in close
    self._upload_next_part()
  File "/usr/local/lib/python3.6/dist-packages/smart_open/s3.py", line 524, in _upload_next_part
    upload = part.upload(Body=self._buf)
  File "/usr/local/lib/python3.6/dist-packages/boto3/resources/factory.py", line 520, in do_action
    response = action(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/usr/lib/python3/dist-packages/botocore/client.py", line 324, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.6/dist-packages/ddtrace/contrib/botocore/patch.py", line 157, in patched_api_call
    result = original_func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/botocore/client.py", line 609, in _make_api_call
    operation_model, request_dict)
  File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 143, in make_request
    return self._send_request(request_dict, operation_model)
  File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 172, in _send_request
    success_response, exception):
  File "/usr/lib/python3/dist-packages/botocore/endpoint.py", line 265, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/usr/lib/python3/dist-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/usr/lib/python3/dist-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/usr/lib/python3/dist-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
**ValueError: filedescriptor out of range in select()**

Frequency is 200 requests per 5 seconds. We are already on python 3.x, and we saw only one relevant document in stackoverflow regarding this error:

"filedescriptor out of range in select()" when using python's subprocess with rsync - Stack Overflow

.Can somebody guide me as to what steps we should take further?

Hi @Tishant_Chandrakar - Can you provide further information? The more details the better (sample code, logs from the SDK, etc.). From the stack trace, I do not see anything related to Couchbase.

@jcasey This is the complete stack trace for this error.

Traceback (most recent call last):,
        File \/usr/local/lib/python3.6/dist-packages/flask/app.py\, line 1949, in full_dispatch_request,
          rv = self.dispatch_request(),
        File \/usr/local/lib/python3.6/dist-packages/flask/app.py\, line 1935, in dispatch_request,
          return self.view_functions[rule.endpoint](**req.view_args),
        File \./rest_api/include.py\, line 865, in _wrapper,
          ret = func(reqData),
        File \./rest_api/exportApi.py\, line 677, in wrapper,
          locale=locale,,
        File \./rest_api/exportApi.py\, line 600, in wrapper,
          s3file.write(buf.getvalue()),
        File \/usr/local/lib/python3.6/dist-packages/smart_open/s3.py\, line 538, in __exit__,
          self.close(),
        File \/usr/local/lib/python3.6/dist-packages/smart_open/s3.py\, line 452, in close,
          self._upload_next_part(),
        File \/usr/local/lib/python3.6/dist-packages/smart_open/s3.py\, line 524, in _upload_next_part,
          upload = part.upload(Body=self._buf),
        File \/usr/local/lib/python3.6/dist-packages/boto3/resources/factory.py\, line 520, in do_action,
          response = action(self, *args, **kwargs),
        File \/usr/local/lib/python3.6/dist-packages/boto3/resources/action.py\, line 83, in __call__,
          response = getattr(parent.meta.client, operation_name)(**params),
        File \/usr/lib/python3/dist-packages/botocore/client.py\, line 324, in _api_call,
          return self._make_api_call(operation_name, kwargs),
        File \/usr/lib/python3/dist-packages/botocore/client.py\, line 609, in _make_api_call,
          operation_model, request_dict),
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 143, in make_request,
          return self._send_request(request_dict, operation_model),
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 172, in _send_request,
          success_response, exception):,
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 265, in _needs_retry,
          caught_exception=caught_exception, request_dict=request_dict),
        File \/usr/lib/python3/dist-packages/botocore/hooks.py\, line 227, in emit,
          return self._emit(event_name, kwargs),
        File \/usr/lib/python3/dist-packages/botocore/hooks.py\, line 210, in _emit,
          response = handler(**kwargs),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 183, in __call__,
          if self._checker(attempts, response, caught_exception):,
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 251, in __call__,
          caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 269, in _should_retry,
          return self._checker(attempt_number, response, caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 317, in __call__,
          caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 223, in __call__,
          attempt_number, caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 359, in _check_caught_excepti,
          raise caught_exception,
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 213, in _get_response,
          proxies=self.proxies, timeout=self.timeout),
        File \/usr/lib/python3/dist-packages/requests/sessions.py\, line 630, in send,
          r = adapter.send(request, **kwargs),
        File \/usr/lib/python3/dist-packages/requests/adapters.py\, line 440, in send,
          timeout=timeout,
        File \/usr/lib/python3/dist-packages/urllib3/connectionpool.py\, line 601, in urlopen,
          chunked=chunked),
        File \/usr/lib/python3/dist-packages/urllib3/connectionpool.py\, line 357, in _make_request,
          conn.request(method, url, **httplib_request_kw),
        File \/usr/lib/python3.6/http/client.py\, line 1281, in request,
          self._send_request(method, url, body, headers, encode_chunked),
        File \/usr/lib/python3/dist-packages/botocore/awsrequest.py\, line 130, in _send_request,
          self, method, url, body, headers, *args, **kwargs),
        File \/usr/lib/python3.6/http/client.py\, line 1327, in _send_request,
          self.endheaders(body, encode_chunked=encode_chunked),
        File \/usr/lib/python3.6/http/client.py\, line 1276, in endheaders,
          self._send_output(message_body, encode_chunked=encode_chunked),
        File \/usr/lib/python3/dist-packages/botocore/awsrequest.py\, line 163, in _send_output,
          read, write, exc = select.select([self.sock], [], [self.sock], 1),
      ValueError: filedescriptor out of range in select()

I have also tried to apply the mentioned solution using libcouchbase2-libevent from here: Couchbase C SDK Release Notes and Download Archives | Couchbase Docs but its not working.

Traceback (most recent call last):,
        File \/usr/local/lib/python3.6/dist-packages/flask/app.py\, line 1949, in full_dispatch_request,
          rv = self.dispatch_request(),
        File \/usr/local/lib/python3.6/dist-packages/flask/app.py\, line 1935, in dispatch_request,
          return self.view_functions[rule.endpoint](**req.view_args),
        File \./rest_api/include.py\, line 865, in _wrapper,
          ret = func(reqData),
        File \./rest_api/exportApi.py\, line 677, in wrapper,
          locale=locale,,
        File \./rest_api/exportApi.py\, line 600, in wrapper,
          s3file.write(buf.getvalue()),
        File \/usr/local/lib/python3.6/dist-packages/smart_open/s3.py\, line 538, in __exit__,
          self.close(),
        File \/usr/local/lib/python3.6/dist-packages/smart_open/s3.py\, line 452, in close,
          self._upload_next_part(),
        File \/usr/local/lib/python3.6/dist-packages/smart_open/s3.py\, line 524, in _upload_next_part,
          upload = part.upload(Body=self._buf),
        File \/usr/local/lib/python3.6/dist-packages/boto3/resources/factory.py\, line 520, in do_action,
          response = action(self, *args, **kwargs),
        File \/usr/local/lib/python3.6/dist-packages/boto3/resources/action.py\, line 83, in __call__,
          response = getattr(parent.meta.client, operation_name)(**params),
        File \/usr/lib/python3/dist-packages/botocore/client.py\, line 324, in _api_call,
          return self._make_api_call(operation_name, kwargs),
        File \/usr/lib/python3/dist-packages/botocore/client.py\, line 609, in _make_api_call,
          operation_model, request_dict),
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 143, in make_request,
          return self._send_request(request_dict, operation_model),
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 172, in _send_request,
          success_response, exception):,
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 265, in _needs_retry,
          caught_exception=caught_exception, request_dict=request_dict),
        File \/usr/lib/python3/dist-packages/botocore/hooks.py\, line 227, in emit,
          return self._emit(event_name, kwargs),
        File \/usr/lib/python3/dist-packages/botocore/hooks.py\, line 210, in _emit,
          response = handler(**kwargs),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 183, in __call__,
          if self._checker(attempts, response, caught_exception):,
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 251, in __call__,
          caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 269, in _should_retry,
          return self._checker(attempt_number, response, caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 317, in __call__,
          caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 223, in __call__,
          attempt_number, caught_exception),
        File \/usr/lib/python3/dist-packages/botocore/retryhandler.py\, line 359, in _check_caught_excepti,
          raise caught_exception,
        File \/usr/lib/python3/dist-packages/botocore/endpoint.py\, line 213, in _get_response,
          proxies=self.proxies, timeout=self.timeout),
        File \/usr/lib/python3/dist-packages/requests/sessions.py\, line 630, in send,
          r = adapter.send(request, **kwargs),
        File \/usr/lib/python3/dist-packages/requests/adapters.py\, line 440, in send,
          timeout=timeout,
        File \/usr/lib/python3/dist-packages/urllib3/connectionpool.py\, line 601, in urlopen,
          chunked=chunked),
        File \/usr/lib/python3/dist-packages/urllib3/connectionpool.py\, line 357, in _make_request,
          conn.request(method, url, **httplib_request_kw),
        File \/usr/lib/python3.6/http/client.py\, line 1281, in request,
          self._send_request(method, url, body, headers, encode_chunked),
        File \/usr/lib/python3/dist-packages/botocore/awsrequest.py\, line 130, in _send_request,
          self, method, url, body, headers, *args, **kwargs),
        File \/usr/lib/python3.6/http/client.py\, line 1327, in _send_request,
          self.endheaders(body, encode_chunked=encode_chunked),
        File \/usr/lib/python3.6/http/client.py\, line 1276, in endheaders,
          self._send_output(message_body, encode_chunked=encode_chunked),
        File \/usr/lib/python3/dist-packages/botocore/awsrequest.py\, line 163, in _send_output,
          read, write, exc = select.select([self.sock], [], [self.sock], 1),
      ValueError: filedescriptor out of range in select()

@jcasey please checkout the complete stack trace and let me know if there is any solution available. This is the document that I followed: Couchbase C SDK Release Notes and Download Archives | Couchbase Docs