Skip to content

Fix/aiohttp call#137

Merged
lzsweb merged 6 commits into
mainfrom
fix/aiohttp-call
Jun 15, 2026
Merged

Fix/aiohttp call#137
lzsweb merged 6 commits into
mainfrom
fix/aiohttp-call

Conversation

@lzsweb

@lzsweb lzsweb commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Description

[Describe what this PR does and why]

Related Issue: Fixes #[issue_number] or Relates to #[issue_number]

Security Considerations: [Check if API keys or sensitive credentials are exposed in code/logs]

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Model
  • Application
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

[How to test these changes]

Additional Notes

[Optional: any other context]

zhansheng.lzs and others added 2 commits June 12, 2026 14:12
Replace per-request aiohttp.ClientSession creation with a shared session
pool (one per event loop) to enable HTTP connection reuse across async API
calls. SSL context is cached and shared across all sessions.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Streaming requests were using aiohttp.ClientTimeout(total=...) which kills
the connection after the deadline even if the model is still actively
producing tokens. Switch to ClientTimeout(sock_read=...) for streaming
requests so the timeout only triggers on idle connections (no data between
chunks). Non-streaming requests still use total timeout.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a shared aiohttp session pool (aio_session.py) to enable connection reuse across asynchronous API calls, updating aiohttp_request.py and http_request.py to utilize these shared sessions and refining timeout configurations for streaming and non-streaming requests. Feedback focuses on two key issues: first, using id(loop) as a dictionary key is unsafe due to potential ID reuse, and should be replaced with a weakref.WeakKeyDictionary using the loop object itself; second, streaming requests require total=None in ClientTimeout to prevent them from timing out after the default 5-minute limit.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread dashscope/api_entities/aio_session.py Outdated
Comment thread dashscope/api_entities/aio_session.py
Comment thread dashscope/api_entities/aio_session.py
Comment thread dashscope/api_entities/aiohttp_request.py
Comment thread dashscope/api_entities/http_request.py
Comment thread tests/unit/test_aio_session.py Outdated
The atexit handler created a new event loop to close sessions bound to
the original loop, which silently failed. OS reclaims resources on exit,
so explicit close is unnecessary. Also adds stale-entry cleanup in
get_shared_aio_session() to prevent unbounded dict growth when event
loops are repeatedly created and closed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lzsweb lzsweb force-pushed the fix/aiohttp-call branch from 1f3275a to 3a8e5fa Compare June 12, 2026 09:32
zhansheng.lzs and others added 3 commits June 15, 2026 11:12
…ings to English

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lzsweb lzsweb merged commit 6475159 into main Jun 15, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

1 participant