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

fix(yamux): future leak #1171

Merged
merged 2 commits into from
Aug 12, 2024
Merged

fix(yamux): future leak #1171

merged 2 commits into from
Aug 12, 2024

Conversation

lchenut
Copy link
Collaborator

@lchenut lchenut commented Aug 9, 2024

At first glance, this fixes #1165.

It raises another issue: I always thought that Future unfinished caught in the GC were cancelled. But that doesn't always seem to be the case.

@lchenut lchenut changed the title fix: yamux future leak fix(yamux): future leak Aug 9, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.54%. Comparing base (02c96fc) to head (5e7314f).
Report is 44 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #1171    +/-   ##
========================================
  Coverage   84.53%   84.54%            
========================================
  Files          91       92     +1     
  Lines       15517    16424   +907     
========================================
+ Hits        13118    13885   +767     
- Misses       2399     2539   +140     
Files Coverage Δ
libp2p/muxers/yamux/yamux.nim 86.38% <100.00%> (+1.84%) ⬆️

... and 80 files with indirect coverage changes

await closedRemotelyFut.cancelAndWait()
if not receivedDataFut.finished():
await receivedDataFut.cancelAndWait()
await closedRemotelyFut or receivedDataFut
Copy link
Collaborator

@diegomrsantos diegomrsantos Aug 11, 2024

Choose a reason for hiding this comment

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

It is probably better to use

proc raceCancel*(
    futs: seq[InternalRaisesFuture]
): Future[FutureBase] {.async: (raises: [ValueError, CancelledError]).} =
  try:
    discard await race(futs)
  finally:
    await noCancel allFutures(futs.filterIt(not it.finished).mapIt(it.cancelAndWait))

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's also going to handle cancelations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not a huge fan of using InternalRaisesFuture outside of Chronos tbh.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Me neither, but that's the only way for now, unless SomeFuture is changed to public.

@lchenut lchenut mentioned this pull request Aug 12, 2024
@lchenut lchenut merged commit 55cc543 into master Aug 12, 2024
14 checks passed
@lchenut lchenut deleted the fix-yamux-leak branch August 12, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

bug: yamux Futures leak
3 participants