Skip to content

Conversation

@ela-kotulska-frequenz
Copy link
Contributor

The ready() method was not terminating when close() was called, causing it to hang indefinitely. This fix ensures ready() returns False when the receiver is closed.

@ela-kotulska-frequenz ela-kotulska-frequenz self-assigned this Jun 16, 2025
Copilot AI review requested due to automatic review settings June 16, 2025 13:58
@ela-kotulska-frequenz ela-kotulska-frequenz added the type:bug Something isn't working label Jun 16, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz requested a review from a team as a code owner June 16, 2025 13:58
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:experimental Affects the experimental package labels Jun 16, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that NopReceiver.ready() unblocks and returns False when close() is called, preventing it from hanging indefinitely.

  • Replace the _closed flag with a future (_ready_future) to signal closure to ready().
  • Update ready(), consume(), and close() to use the new future-based mechanism.
  • Add a test that verifies ready() returns False immediately after close().
  • Note the bugfix in RELEASE_NOTES.md.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/experimental/test_nop_receiver.py Added test_close_method_effect_on_ready to check that ready() terminates when closed.
src/frequenz/channels/experimental/_nop_receiver.py Swapped the _closed boolean for _ready_future and updated ready(), consume(), and close().
RELEASE_NOTES.md Documented the fix for NopReceiver.ready() closure behavior.

Comment on lines +53 to +57
# Create a task that waits for the receiver to be ready.
task = asyncio.create_task(receiver.ready())

# Wait for the task to start.
await asyncio.sleep(0.1)
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Relying on sleep can lead to flaky tests; consider using an asyncio.Event or polling task.done() to deterministically wait until the task is awaiting ready().

Suggested change
# Create a task that waits for the receiver to be ready.
task = asyncio.create_task(receiver.ready())
# Wait for the task to start.
await asyncio.sleep(0.1)
# Create an event to signal when the task starts.
task_started = asyncio.Event()
async def wait_for_ready():
task_started.set() # Signal that the task has started.
return await receiver.ready()
# Create a task that waits for the receiver to be ready.
task = asyncio.create_task(wait_for_ready())
# Wait for the task to start.
await task_started.wait()

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I need to make sure ready is called before cancel.
This won't do that.

The ready() method was not terminating when close() was called, causing
it to hang indefinitely. This fix ensures ready() returns False when
the receiver is closed.

Signed-off-by: Elzbieta Kotulska <[email protected]>
Because it is recommended in the python documentation.
This way alternative event loop implementations can inject their
own optimized implementations of a Future object.

Signed-off-by: Elzbieta Kotulska <[email protected]>
Copy link
Contributor

@shsms shsms left a comment

Choose a reason for hiding this comment

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

oops

@ela-kotulska-frequenz ela-kotulska-frequenz changed the title Make NopReceiver.ready() respond to close() method Fix NopReceiver.ready() to properly terminate when receiver is closed. Jun 17, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz changed the title Fix NopReceiver.ready() to properly terminate when receiver is closed. Fix NopReceiver.ready() to properly terminate when receiver is closed. Jun 17, 2025
@ela-kotulska-frequenz ela-kotulska-frequenz added this pull request to the merge queue Jun 17, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit 468500c Jun 17, 2025
5 checks passed
@ela-kotulska-frequenz ela-kotulska-frequenz deleted the fix_nop_receiver branch June 17, 2025 09:15
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

I guess it doesn't matter as long as it works, but maybe using a Event would be less low-level-ish.

@llucax llucax added this to the v1.10.0 milestone Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:experimental Affects the experimental package part:tests Affects the unit, integration and performance (benchmarks) tests type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants