AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Tee Leaves Source Generator Open When A Child Iterator Is Never Started

The Tee context manager in langchain-core does not close the underlying source generator if one or more child iterators are never started, causing resource leaks.

highConfidence 95%LangchainAffected V1.6.6

Origin Analysis

Unstarted child iterators do not execute their finally blocks when closed, leaving their registered buffers active and preventing the source generator from being closed.
Run the provided sync and async reproduction code. Observe that 'sync source closed: False' and 'async source closed: False' are printed, indicating the source's finally block did not execute.

Fixing Code Block

Edge Case Audit

Ensure the source generator is not closed elsewhere before the Tee context exits, as this would cause a double-close. The fix may affect performance if many unstarted children exist. Rollback by reverting to the original __exit__/__aexit__ methods.

Ecosystem Topology