Skip to content

Conversation

mk-armah
Copy link
Member

@mk-armah mk-armah commented Oct 8, 2025

User description

Description

What
This PR fixes a bug in the RetryTransport class where the _log_response_size_async method was consuming the HTTPX response stream using await response.aread() while logging.
This caused downstream consumers (such as pagination handlers) to raise StreamConsumed errors when attempting to access the already-read stream.

Why
The response body was being read prematurely during logging, making it unavailable for the actual consumer of the response. This broke async pagination and retry flows in integrations that depend on reusing the same response object for subsequent reads.

How

  • Removed the direct call to await response.aread() inside _log_response_size_async.
  • Replaced it with a non-destructive approach that uses the Content-Length header where available.
  • If the header is missing, the method now logs skip computing the size instead of reading the stream.
  • Added logging guard to ensure response size logging runs only when explicitly enabled.

Type of change

Please leave one option from the following and delete the rest:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New Integration (non-breaking change which adds a new integration)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Non-breaking change (fix of existing functionality that will not change current behavior)
  • Documentation (added/updated documentation)

All tests should be run against the port production environment(using a testing org).

Core testing checklist

  • Integration able to create all default resources from scratch
  • Resync finishes successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Scheduled resync able to abort existing resync and start a new one
  • Tested with at least 2 integrations from scratch
  • Tested with Kafka and Polling event listeners
  • Tested deletion of entities that don't pass the selector

Integration testing checklist

  • Integration able to create all default resources from scratch
  • Completed a full resync from a freshly installed integration and it completed successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Resync finishes successfully
  • If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the examples folder in the integration directory.
  • If resource kind is updated, run the integration with the example data and check if the expected result is achieved
  • If new resource kind is added or updated, validate that live-events for that resource are working as expected
  • Docs PR link here

Preflight checklist

  • Handled rate limiting
  • Handled pagination
  • Implemented the code in async
  • Support Multi account

Screenshots

Include screenshots from your environment showing how the resources of the integration will look.

API Documentation

Provide links to the API documentation used for this integration.


PR Type

Bug fix


Description

  • Fix StreamConsumed error in RetryTransport response logging

  • Remove stream consumption from response size logging methods

  • Use Content-Length header only for size logging

  • Skip logging when Content-Length header is missing


Diagram Walkthrough

flowchart LR
  A["Response received"] --> B["Check Content-Length header"]
  B --> C{Header exists?}
  C -->|Yes| D["Log size from header"]
  C -->|No| E["Skip logging"]
  D --> F["Stream remains unconsumed"]
  E --> F
Loading

File Walkthrough

Relevant files
Bug fix
retry.py
Fix stream consumption in response logging                             

port_ocean/helpers/retry.py

  • Remove await response.aread() and response.read() calls from logging
    methods
  • Use only Content-Length header for response size logging
  • Skip logging when Content-Length header is missing
  • Simplify error handling by avoiding stream consumption
+8/-25   
Documentation
CHANGELOG.md
Add changelog entry for bug fix                                                   

CHANGELOG.md

  • Add entry for version 0.28.13
  • Document StreamConsumed error fix in bug fixes section
+8/-0     
Configuration changes
pyproject.toml
Version bump to 0.28.13                                                                   

pyproject.toml

  • Bump version from 0.28.12 to 0.28.13
+1/-1     

@mk-armah mk-armah requested a review from a team as a code owner October 8, 2025 19:32
@github-actions github-actions bot added the size/S label Oct 8, 2025
Copy link
Contributor

qodo-merge-pro bot commented Oct 8, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Copy link
Contributor

qodo-merge-pro bot commented Oct 8, 2025

PR Code Suggestions ✨

No code suggestions found for the PR.

Copy link
Contributor

@shalev007 shalev007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

github-actions bot commented Oct 8, 2025

Code Coverage Artifact 📈: https://github.com/port-labs/ocean/actions/runs/18355907461/artifacts/4219263056

Code Coverage Total Percentage: 87.54%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants