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

How to initiate disconnection? #127

Open
adamradocz opened this issue Dec 10, 2021 · 6 comments · May be fixed by #130
Open

How to initiate disconnection? #127

adamradocz opened this issue Dec 10, 2021 · 6 comments · May be fixed by #130

Comments

@adamradocz
Copy link
Contributor

How to disconnect the client from the server?

@adamradocz adamradocz changed the title How to initiate a disconnection? How to initiate disconnection? Dec 10, 2021
This was referenced Dec 11, 2021
@KieranDevvs
Copy link

Im currently using ConnectionContext.Abort();

@adamradocz
Copy link
Contributor Author

Yes, I tried that one as well. The problem with that is, when I tested the ConnectionContext.Abort(); the server didn't receive the IsCompleted nor the IsCancelled result. You can check it for yourself, if you add logging at the start and at the end of the OnConnectedAsync() method.

Though when I explicitly called the await connection.DisposeAsync();, the server received the IsCompleted result.

I created a PR for that: #130

@KieranDevvs
Copy link

KieranDevvs commented Dec 11, 2021

Shouldnt BaseConnectionContext also have a way of getting the connection state i.e if its closed, disconnected or connected?
Im currently using the cancellation token to see if the context should still be read from but it feels wrong.
I know you can use the features to get the socket state if the connection is a socket etc but surely the connection state of a "ConnectionContext" should be known independent of a transport?

public virtual CancellationToken ConnectionClosed

while (!connectionContext.ConnectionClosed.IsCancellationRequested)
{
    await connectionSession.Reader.ReadAsync(_protocol);
    var packet = result.Message;

    //.... Handle packet ....
}

@davidfowl
Copy link
Owner

Abort is the way to disconnect the transport for sure.

@adamradocz
Copy link
Contributor Author

@davidfowl In #130 PR. In the samples/ClientApplication/Program.cs at line 366, if I replace the await connection.DisposeAsync(); for connection.Abort(); nothing happens. The server won't receive IsCompleted nor IsCancelled result.

@davidfowl
Copy link
Owner

Calling DisposeAsync to abort is incorrect. Calling Abort should work, if it doesn't work then there's a bug. DisposeAsync is implicitly called by the pipeline when the code unwinds.

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 a pull request may close this issue.

3 participants