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

multiplex: add (*Multiplex).CloseChan #87

Closed
wants to merge 1 commit into from

Conversation

zllovesuki
Copy link
Contributor

This commit exposes the underlying mp.closed channel to the caller, and allows the caller
to receive an event on session closed.

This commit exposes the underlying mp.closed channel to the caller, and allows the caller
to receive an event on session closed.
@marten-seemann
Copy link
Contributor

Which problem does this solve? When the session is closed, the caller will notice this the next time he calls any of the functions (like opening / accepting new streams), right?

@zllovesuki
Copy link
Contributor Author

In my use case, when a session is closed, another goroutine needs to remove all states associated with the session as soon as possible. Currently, I'm using a time.Ticker checking IsClosed every 500 milliseconds, then close the read-only channel. This is not ideal, when the package already has a mechanism to actively let the caller know that the session is closed.

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

Looks like we've set a precedent for exactly this kind of function with go-yamux: https://pkg.go.dev/github.com/libp2p/go-yamux#Session.CloseChan.

Just for reference, in quic-go we chose to (ab?)use a context for this: https://pkg.go.dev/github.com/lucas-clemente/quic-go#Session, thereby combining IsClosed and CloseChan into one method. Not sure if that's the nicer API choice.

}

go func() {
time.Sleep(time.Second * 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a time.Sleep here? This could be executed immediately, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we don't need the .Sleep here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in force push

Copy link
Contributor Author

Choose a reason for hiding this comment

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

huh, GitHub doesn't work like bitbucket does. It doesn't seem to update from force push.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my apology, I clicked to use the wrong branch as the source. I will close this one and use the correct branch.

case <-ctx.Done():
t.Fatal("did not receive from CloseChan within timeout")
case <-mpb.CloseChan():
case <-mpa.CloseChan():
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a second select statement, to make sure that both mpa and mpb are closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I should probably do a second one to make sure that both got the "message"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in force push

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would you mind closing this PR and instead look at #89 instead? Sorry for the mix up.

Copy link
Contributor

Choose a reason for hiding this comment

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

GitHub should allow you to force push, and update the PR accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Next time then ;)
Let’s continue in #89 for now, that’s easier.

@marten-seemann
Copy link
Contributor

Closing in favor of #89, as requested.

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