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

Unable to wait for socket closure #53

Closed
andrewjw1995 opened this issue Aug 16, 2020 · 2 comments
Closed

Unable to wait for socket closure #53

andrewjw1995 opened this issue Aug 16, 2020 · 2 comments

Comments

@andrewjw1995
Copy link

As far as I can tell, there's no way to receive a callback when the socket used by SocketConnection is closed or disposed. I'd like to make a proxy server which accepts connections using a proprietary protocol, unpacks the messages from that protocol, and sends the content on to another server. I'll end up with two SocketConnections, and a class which is translating between them. When one SocketConnection is closed, I need to close the other one to ensure I'm not leaking connections.

  • I could include a 'disconnect' message in the protocol, but that doesn't handle network errors or application errors
  • I could poll the SocketConnection, but that seems too hacky

Ideally, I'd like to register a callback, or be able to await a task, so I can run some cleanup code once either of the two sockets has disconnected.

@andrewjw1995 andrewjw1995 changed the title Unable to await socket closure Unable to wait for socket closure Aug 16, 2020
@xqrzd
Copy link

xqrzd commented Aug 28, 2020

You'll be notified of this in your main parsing loop, when PipeReader.ReadAsync() returns a status of canceled, completed, or throws an exception.

@andrewjw1995
Copy link
Author

@xqrzd that makes more sense - I was waiting for ReadAsync() to return a status of canceled or completed, but it was throwing an exception instead. The documentation for PipeReader does not indicate that this method can throw an exception, so I was not handling it. I think perhaps the readme for this repo could be updated to show how to make a basic proxy, as it's a very simple use case and it would demonstrate where network exceptions need to be caught, for both PipeReader and PipeWriter

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

No branches or pull requests

2 participants