Skip to content
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

refactor(helper/streaming): Avoid attaching AbortSignal on newer versions of Bun #3859

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

Jarred-Sumner
Copy link
Contributor

While investigating a memory leak, I noticed that the streams helpers in hono unconditionally attach an AbortSignal to each request. As of Bun v1.1.27, we call cancel on ReadableStream so this should be unnecessary.

I verified that on Bun v1.1.26, hardcoding the isOldBunVersion function to return false caused the abort-related tests to hang and that on Bun v1.2 hardcoding the isOldBunVersion function to return false those tests pass.

There is duplicate code but it felt less invasive to duplicate the code.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@yusukebe
Copy link
Member

@Jarred-Sumner Thank you for the PR.

Hey @sor4chi, The CI is falling. Should we update the tests?

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.33%. Comparing base (d40fffb) to head (f4d56ec).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3859      +/-   ##
==========================================
+ Coverage   91.32%   91.33%   +0.01%     
==========================================
  Files         161      162       +1     
  Lines       10242    10257      +15     
  Branches     2889     2904      +15     
==========================================
+ Hits         9353     9368      +15     
  Misses        888      888              
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// Emulate an old version of Bun (version 1.1.0) for this specific test case
// @ts-expect-error Bun is not typed
global.Bun = {
version: '1.1.0',
Copy link
Member

Choose a reason for hiding this comment

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

To pass the test, specify the old version at the global.

@yusukebe
Copy link
Member

I fixed the tests and unified the functions as one function in utils.ts. Looks good. I'll merge this.

@Jarred-Sumner Thanks!

@yusukebe yusukebe merged commit d72aa4b into honojs:main Jan 27, 2025
16 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.

2 participants