-
Notifications
You must be signed in to change notification settings - Fork 266
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
fix: cancel all outgoing requests when disconnect to prevent ANR #501
Conversation
} | ||
return v.(Transport) | ||
} | ||
var Debug = log.New(io.Discard, "[DEBUG] ", log.LstdFlags) |
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.
This is not an efficient way to do logging, because you are still generating the messages, and discarding them. And you can't check the log levels.
Let's use slog instead:
https://pkg.go.dev/log/slog
https://go.dev/blog/slog
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.
updated to slog
Android/app/src/go/backend/doh.go
Outdated
type DoHServer struct { | ||
tspt doh.Transport | ||
} |
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.
type DoHServer struct { | |
tspt doh.Transport | |
} | |
type DoHServer struct { | |
server doh.Server | |
} |
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.
renamed to type DoHServer struct { r doh.Resolver }
Android/app/src/go/backend/tunnel.go
Outdated
*intra.Tunnel | ||
} | ||
|
||
func (s *Session) SetDoHServer(svr *DoHServer) { s.SetDNS(svr.tspt) } |
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.
We pass the server on ConnectSession. Is this ever used?
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.
Yes, user can update the DoH server even during connected session.
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
Co-authored-by: Vinicius Fortuna <[email protected]>
In this PR, I fixed an ANR issue by adding a
context.Context
object to thedoh.Transport.Query
method. Thisctx
will be passed to all network related calls, and it will be cancelled when userDisconnect
s.But if we just simply add
ctx
to the method,gomobile
requires we export all related packages (e.g.,time
) that are used bycontext.Context
, which is not applicable. Therefore we refactored the go code structure and introduced a newbackend
package that will be the only interface that Java code can use.In addition, I retired
github.com/eycorsican/go-tun2socks/common/log
and introduced our ownlogging
package.TODO Items
The refactoring of
backend
package is not done yet (for example,intra
,intra/split
andintra/protect
are still exported to Java), but it will involve a lot of changes that are not related to this PR, therefore I would postpone them to future changes.