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

feat(listener): close with timeout #198

Closed
wants to merge 4 commits into from

Conversation

qzhuyan
Copy link
Collaborator

@qzhuyan qzhuyan commented Jul 3, 2023

No description provided.

@coveralls
Copy link

coveralls commented Jul 3, 2023

Pull Request Test Coverage Report for Build 5934931546

  • 69 of 85 (81.18%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.03%) to 82.99%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/quicer.erl 13 14 92.86%
src/quicer_nif.erl 0 2 0.0%
c_src/quicer_listener.c 51 64 79.69%
Files with Coverage Reduction New Missed Lines %
c_src/quicer_nif.c 1 77.88%
Totals Coverage Status
Change from base Build 5728709000: -0.03%
Covered Lines: 2903
Relevant Lines: 3498

💛 - Coveralls

@qzhuyan qzhuyan marked this pull request as ready for review August 2, 2023 15:35
l_ctx->is_closed = TRUE;
enif_mutex_unlock(l_ctx->lock);

// It is safe to close it without holding the lock
// This also ensures no ongoing listener callbacks
// This is a blocking call. @TODO have async version or use dirty scheduler

Choose a reason for hiding this comment

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

was the TODO removed on purpose or by accident? (as it's not related to this change)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could use ListenerStop for async calls instead and keep ListenerCLose sync.
maybe it is a good time to add ListenerStop support.
I will update the PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a blocking call but it is cheap, that is why the @todo is removed.

l_ctx->is_closed = TRUE;
enif_mutex_unlock(l_ctx->lock);

// It is safe to close it without holding the lock
// This also ensures no ongoing listener callbacks
// This is a blocking call. @TODO have async version or use dirty scheduler
// This is a blocking call.
//
MsQuic->ListenerClose(l);

Choose a reason for hiding this comment

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

is it OK to close the listener if it was already closed? Or should it be better to return just after the critical section if ret != ATOM_OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is ok.
L476 set it to NULL and ListenerClose has _Pre_defensive_ annotation. So it will never trigger use-after-free.

case quicer_nif:close_listener(Listener) of
ok ->
receive
{quic, listener_stopped, Listener} ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The event is only shot to the Listener owner who opens the listener.
The timeout prevents long blocking on the caller who is not the owner.
maybe we should check the owner ship in NIF and return {error, not_owner}

@qzhuyan qzhuyan force-pushed the dev/william/close-listener-timeout branch from 8759833 to ca76eeb Compare August 22, 2023 05:42
@qzhuyan
Copy link
Collaborator Author

qzhuyan commented Aug 22, 2023

replaced with #205

@qzhuyan qzhuyan closed this Aug 22, 2023
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.

3 participants