Skip to content

Commit

Permalink
fix errors.Is nil reference panic
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Feb 21, 2024
1 parent 43de898 commit 49c62e4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Android/app/src/go/doh/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,15 @@ func (t *transport) Query(ctx context.Context, q []byte) ([]byte, error) {
response, server, qerr := t.doQuery(ctx, q)
after := time.Now()

errIsCancel := false
var err error
status := Complete
httpStatus := http.StatusOK
if qerr != nil {
err = qerr
status = qerr.status
httpStatus = 0
errIsCancel = errors.Is(qerr, context.Canceled)

var herr *httpError
if errors.As(qerr.err, &herr) {
Expand All @@ -461,14 +463,13 @@ func (t *transport) Query(ctx context.Context, q []byte) ([]byte, error) {
// the following deadlock:
// 1. Java - synchronized VpnController.stop()
// 2. Go - context.Cancel()
// 3. Go - errors.Is(qerr, context.Cancelled)
// 4. Go - (if we don't stop sending OnResponse)
// 5. Java - GoIntraListener.onResponse
// 6. Java - synchronized VpnController.onConnectionStateChanged()
// 3. Go - (if we don't stop sending OnResponse)
// 4. Java - GoIntraListener.onResponse
// 5. Java - synchronized VpnController.onConnectionStateChanged()
// Deadlock happens (both Step 1 and Step 6 are marked as synchronized)!
//
// TODO: make stop() an asynchronized function
if t.listener != nil && !errors.Is(qerr, context.Canceled) {
if t.listener != nil && !errIsCancel {
latency := after.Sub(before)
var ip string
if server != nil {
Expand Down

0 comments on commit 49c62e4

Please sign in to comment.