-
Notifications
You must be signed in to change notification settings - Fork 55
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: stop all active connections on Proxy.Stop() #206
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. Apart from this PR, shall we introduce a Close
or Shutdown
function to every StreamDialer
, I feel it's a common feature for a StreamDialer
to stop the connections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments addressed. It turns out it's more complicated than I thought.
I'm now handling the case where stop happens before or during DialStream.
I added tests to ensure I'm covering all the cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic looks good, but please double check the package comment.
x/mobileproxy/stop_dialer_test.go
Outdated
// Package mobileproxy provides convenience utilities to help applications run a local proxy | ||
// and use that to configure their networking libraries. | ||
// | ||
// This package is suitable for use with Go Mobile, making it a convenient way to integrate with mobile apps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Package mobileproxy provides convenience utilities to help applications run a local proxy | |
// and use that to configure their networking libraries. | |
// | |
// This package is suitable for use with Go Mobile, making it a convenient way to integrate with mobile apps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyyi1 Please take another look.
I rethought this PR, and it's much simpler now. Instead of driving the cancelation via the dialer, it's much easier if we drive the cancelation via the client connection. We use a base context to notify the handlers the request is cancelled.
We can use context.AfterFunc like you suggested, but we need to upgrade to 1.21 first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's a lot simpler now!
This is to ensure no connection lingers around. I'm hoping this will fix the issue on iOS. With this change, Shutdown always returns quickly.
I also realized that the Hijacker returns a bufio.readWriter, so we might as well leverage the buffer that the http server already allocated in the io.Copy. It implements ReadFrom and WriteTo.