Skip to content

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Nov 18, 2024

Fixes some bugs in the new request cache:

  1. When stopping the client we were supposed to remove the response cache, instead we were deleting an item from the cache
  2. When stopping we were voiding the cache deletion - this can cause unhandled promise rejections so switches to awaiting the promise instead
  3. When starting the cache was being created asynchronously but without waiting for the promise to resolve, so you could stop the client before the cache was intialized which would mean it is never cleaned up

Also not a bug but it also makes the cache name configurable.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Fixes some bugs in the new request cache:

1. When stopping the client we were supposed to remove the response
    cache, instead we were deleting an item from the cache
2. When stopping we were `void`ing the cache deletion - this can
    cause unhandeled promise rejections so switches to `await`ing
    the promise instead
3. When starting the cache was being created asynchronously but without
    waiting for the promise to resolve, so you could stop the client
    before the cache was intialized which would mean it is never
    cleaned up
@achingbrain achingbrain requested a review from a team as a code owner November 18, 2024 15:33
Copy link
Member

@2color 2color left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for catching these.

@2color
Copy link
Member

2color commented Nov 18, 2024

Btw, are you certain that we call start in consumers of the client (Helia and libp2p)?

@achingbrain
Copy link
Member Author

Yes, we call .start and .stop from the locations you link to.

@achingbrain
Copy link
Member Author

Also sorry for not getting to the review of #151 in time, this PR is me doing it post-merge.

@achingbrain achingbrain merged commit 1c54723 into main Nov 19, 2024
19 checks passed
@achingbrain achingbrain deleted the fix/cache-leak branch November 19, 2024 09:35
github-actions bot pushed a commit that referenced this pull request Nov 19, 2024
## [@helia/delegated-routing-v1-http-api-client-v4.2.1](https://github.com/ipfs/helia-delegated-routing-v1-http-api/compare/@helia/delegated-routing-v1-http-api-client-4.2.0...@helia/delegated-routing-v1-http-api-client-4.2.1) (2024-11-19)

### Bug Fixes

* fixes cache leak and unhandled promise rejection ([#152](#152)) ([1c54723](1c54723))
Copy link

🎉 This PR is included in version @helia/delegated-routing-v1-http-api-client-v4.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants