Skip to content

fix: fix possible non-termination in ingest_drop().#38

Open
zicklag wants to merge 1 commit into
earthstar-project:mainfrom
zicklag:fix/ingest_drop
Open

fix: fix possible non-termination in ingest_drop().#38
zicklag wants to merge 1 commit into
earthstar-project:mainfrom
zicklag:fix/ingest_drop

Conversation

@zicklag
Copy link
Copy Markdown

@zicklag zicklag commented Jan 1, 2025

Fixes an issue where ingest_drop() may not terminate.

I ran into this issue while adding a way to import drops in earthstar. I'm honestly not sure why the same issue isn't run into in the willow test cases, but I do have a failing test case in a PR to the Earthstar repo.

The issue is that we are pushing chunks into the FIFO and then later here, we are triggering a for await loop that will never end because the FIFO has no concept of an EOF or terminating message.

Then a little bit further down the code we are awaiting on the promise running that endless loop, so that we never finish.

This gets around the issue by wrapping the FIFO in a generator that will properly exit when we push an undefined to it. That way we can indicate the end of the stream.

Copy link
Copy Markdown
Contributor

@sgwilym sgwilym left a comment

Choose a reason for hiding this comment

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

Interesting that there were no failing test cases here for so long! As you're right, this FIFO should never end.

Would you be so kind as to make one modification? This kind of stopping pattern is used elsewhere in the codebase, but uses a symbol instead of undefined (e.g.

fifo: FIFO<Uint8Array | typeof CANCELLATION>;
). This makes it a little clearer what's happening.

Thank you!

@zicklag
Copy link
Copy Markdown
Author

zicklag commented Jan 2, 2025

Ah, great idea I'll do that!

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