Skip to content

fix: Replace aiofile with aiofiles to prevent caio context leak under concurrent execution - #12525

Merged
erichare merged 7 commits into
release-1.9.0from
fix-systemerror-files
Apr 7, 2026
Merged

fix: Replace aiofile with aiofiles to prevent caio context leak under concurrent execution#12525
erichare merged 7 commits into
release-1.9.0from
fix-systemerror-files

Conversation

@erichare

@erichare erichare commented Apr 6, 2026

Copy link
Copy Markdown
Member

aiofile uses caio (kernel AIO) which creates contexts in a global dict that are never cleaned up. Under concurrent execution these accumulate until the OS aio-max-nr limit is exhausted, causing SystemError(11, 'Resource temporarily unavailable'). aiofiles uses thread pools instead and does not have this issue.

Migrates all aiofile.async_open usages across both backend and lfx packages to aiofiles.open.

Based on #12433 by @manav2000, extended to cover all remaining usages.

… concurrent execution

aiofile uses caio (kernel AIO) which creates contexts in a global dict
that are never cleaned up. Under concurrent execution these accumulate
until the OS aio-max-nr limit is exhausted, causing
SystemError(11, 'Resource temporarily unavailable'). aiofiles uses
thread pools instead and does not have this issue.

Migrates all aiofile.async_open usages across both backend and lfx
packages to aiofiles.open.

Based on #12433 by @manav2000, extended to cover all remaining usages.

Co-Authored-By: manav2000 <manav2000@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ddd592fb-2055-421d-84b8-38ce1e1f33ab

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-systemerror-files

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Exercises the exact failure pattern from #12414: multiple concurrent
save-then-immediately-read operations on the storage service. This
would previously trigger SystemError(11, EAGAIN) after ~150-200 runs
with the aiofile/caio backend.

Co-Authored-By: manav2000 <manav2000@users.noreply.github.com>
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 6, 2026
@codecov

codecov Bot commented Apr 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.39%. Comparing base (60713e3) to head (8a570e7).
⚠️ Report is 5 commits behind head on release-1.9.0.

Files with missing lines Patch % Lines
src/backend/base/langflow/initial_setup/setup.py 25.00% 3 Missing ⚠️
...rc/lfx/custom/directory_reader/directory_reader.py 33.33% 2 Missing ⚠️
...backend/base/langflow/services/flow/flow_runner.py 50.00% 1 Missing ⚠️
src/lfx/src/lfx/load/load.py 66.66% 1 Missing ⚠️
src/lfx/src/lfx/services/settings/base.py 50.00% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (49.26%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-1.9.0   #12525      +/-   ##
=================================================
+ Coverage          50.37%   50.39%   +0.01%     
=================================================
  Files               1933     1937       +4     
  Lines             172918   172750     -168     
  Branches           26641    24219    -2422     
=================================================
- Hits               87112    87056      -56     
+ Misses             84732    84644      -88     
+ Partials            1074     1050      -24     
Flag Coverage Δ
backend 55.91% <66.66%> (-0.05%) ⬇️
frontend 49.38% <ø> (+0.10%) ⬆️
lfx 49.26% <50.00%> (-0.31%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/api/v1/flows_helpers.py 71.07% <100.00%> (ø)
...rc/backend/base/langflow/services/storage/local.py 74.59% <100.00%> (ø)
...backend/base/langflow/services/flow/flow_runner.py 78.47% <50.00%> (ø)
src/lfx/src/lfx/load/load.py 65.38% <66.66%> (ø)
src/lfx/src/lfx/services/settings/base.py 74.00% <50.00%> (ø)
...rc/lfx/custom/directory_reader/directory_reader.py 18.09% <33.33%> (ø)
src/backend/base/langflow/initial_setup/setup.py 53.92% <25.00%> (-2.07%) ⬇️

... and 208 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 30%
30.34% (32137/105907) 63.74% (4112/6451) 31.44% (750/2385)

Unit Test Results

Tests Skipped Failures Errors Time
3182 0 💤 0 ❌ 0 🔥 5m 40s ⏱️

@Cristhianzl Cristhianzl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Apr 7, 2026
@erichare
erichare added this pull request to the merge queue Apr 7, 2026
@erichare
erichare removed this pull request from the merge queue due to a manual request Apr 7, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 7, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 7, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 7, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Apr 7, 2026
@erichare
erichare enabled auto-merge April 7, 2026 21:21
@github-actions github-actions Bot removed the bug Something isn't working label Apr 7, 2026
@github-actions github-actions Bot added the bug Something isn't working label Apr 7, 2026
@erichare
erichare added this pull request to the merge queue Apr 7, 2026
Merged via the queue into release-1.9.0 with commit f30b291 Apr 7, 2026
100 of 101 checks passed
@erichare
erichare deleted the fix-systemerror-files branch April 7, 2026 23:37
Adam-Aghili pushed a commit that referenced this pull request Apr 15, 2026
… concurrent execution (#12525)

* fix: replace aiofile with aiofiles to prevent caio context leak under concurrent execution

aiofile uses caio (kernel AIO) which creates contexts in a global dict
that are never cleaned up. Under concurrent execution these accumulate
until the OS aio-max-nr limit is exhausted, causing
SystemError(11, 'Resource temporarily unavailable'). aiofiles uses
thread pools instead and does not have this issue.

Migrates all aiofile.async_open usages across both backend and lfx
packages to aiofiles.open.

Based on #12433 by @manav2000, extended to cover all remaining usages.

Co-Authored-By: manav2000 <manav2000@users.noreply.github.com>

* test: add concurrent write-then-read regression test for caio EAGAIN fix

Exercises the exact failure pattern from #12414: multiple concurrent
save-then-immediately-read operations on the storage service. This
would previously trigger SystemError(11, EAGAIN) after ~150-200 runs
with the aiofile/caio backend.

Co-Authored-By: manav2000 <manav2000@users.noreply.github.com>

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

---------

Co-authored-by: manav2000 <manav2000@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants