Skip to content

Commit

Permalink
fix: skip zero-len writes in split retrier (#519)
Browse files Browse the repository at this point in the history
I'm not sure why (as zero len writes are apparently no-op in Golang) but the Quad9 resolver (DNSCrypt over TCP) doesn't work without this check.
  • Loading branch information
ignoramous authored Jul 1, 2024
1 parent c285903 commit 27637e0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Android/app/src/go/intra/split/retrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func (r *retrier) Write(b []byte) (int, error) {
r.conn.SetReadDeadline(time.Now().Add(r.timeout))
}
r.mutex.Unlock()

if attempted {
if err == nil {
return n, nil
Expand All @@ -322,11 +323,19 @@ func (r *retrier) Write(b []byte) (int, error) {
// by the retry procedure. Block until we have a final socket (which will
// already have replayed b[:n]), and retry.
<-r.retryCompleteFlag

r.mutex.Lock()
c := r.conn
r.mutex.Unlock()
m, err := c.Write(b[n:])
return n + m, err

// zero len writes are no-ops, but Quad9 servers
// are observed to respond better when these are skipped.
if buf := b[n:]; len(buf) > 0 {
m, e := c.Write(buf)
n += m
err = e
}
return n, err
}
}

Expand Down

0 comments on commit 27637e0

Please sign in to comment.