Skip to content

Connection exception Connection aborted when exporting metrics periodically #4476

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

Open
codeboten opened this issue Mar 11, 2025 · 1 comment · May be fixed by #4477
Open

Connection exception Connection aborted when exporting metrics periodically #4476

codeboten opened this issue Mar 11, 2025 · 1 comment · May be fixed by #4477
Labels
bug Something isn't working

Comments

@codeboten
Copy link
Contributor

Describe your environment

OS: MacOS
Python version: Python 3.11
SDK version: 1.30.0
API version: 1.30.0

What happened?

Ran the demo python app from the getting started on opentelemetry.io and ran into the following exception when exporting metrics:

Traceback (most recent call last):
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 534, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connection.py", line 516, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.asdf/installs/python/3.11.9/lib/python3.11/http/client.py", line 1395, in getresponse
    response.begin()
  File "/Users/alex/.asdf/installs/python/3.11.9/lib/python3.11/http/client.py", line 325, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.asdf/installs/python/3.11.9/lib/python3.11/http/client.py", line 294, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/util/retry.py", line 474, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 534, in _make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/urllib3/connection.py", line 516, in getresponse
    httplib_response = super().getresponse()
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.asdf/installs/python/3.11.9/lib/python3.11/http/client.py", line 1395, in getresponse
    response.begin()
  File "/Users/alex/.asdf/installs/python/3.11.9/lib/python3.11/http/client.py", line 325, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.asdf/installs/python/3.11.9/lib/python3.11/http/client.py", line 294, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/sdk/metrics/_internal/export/__init__.py", line 541, in _receive_metrics
    self._exporter.export(
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py", line 205, in export
    resp = self._export(serialized_data.SerializeToString())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py", line 176, in _export
    return self._session.post(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/dev/opentelemetry-python/.venv/lib/python3.11/site-packages/requests/adapters.py", line 682, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Steps to Reproduce

  1. Following the instructions to get an app running with manual instrumentation for traces/metrics: https://opentelemetry.io/docs/languages/python/getting-started/
  2. Run the application and emit the data to a backend using OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
  3. Send a request to localhost:8080/rolldice to generate a metric
  4. Observe the exception in the logs

Expected Result

No exception when emitting metrics

Actual Result

The exception documented above.

Additional context

No response

Would you like to implement a fix?

Yes

@codeboten codeboten added the bug Something isn't working label Mar 11, 2025
codeboten added a commit to codeboten/opentelemetry-python that referenced this issue Mar 11, 2025
Fix open-telemetry#4476

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
@codeboten codeboten linked a pull request Mar 11, 2025 that will close this issue
6 tasks
@codeboten
Copy link
Contributor Author

After investigating this issue, it appears this may be related to the connection not being returned to the connection pool once the post is completed. If the response is never read, it is also never closed. I submitted a potential fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant