Skip to content

Commit 27637e0

Browse files
authored
fix: skip zero-len writes in split retrier (#519)
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.
1 parent c285903 commit 27637e0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Android/app/src/go/intra/split/retrier.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ func (r *retrier) Write(b []byte) (int, error) {
314314
r.conn.SetReadDeadline(time.Now().Add(r.timeout))
315315
}
316316
r.mutex.Unlock()
317+
317318
if attempted {
318319
if err == nil {
319320
return n, nil
@@ -322,11 +323,19 @@ func (r *retrier) Write(b []byte) (int, error) {
322323
// by the retry procedure. Block until we have a final socket (which will
323324
// already have replayed b[:n]), and retry.
324325
<-r.retryCompleteFlag
326+
325327
r.mutex.Lock()
326328
c := r.conn
327329
r.mutex.Unlock()
328-
m, err := c.Write(b[n:])
329-
return n + m, err
330+
331+
// zero len writes are no-ops, but Quad9 servers
332+
// are observed to respond better when these are skipped.
333+
if buf := b[n:]; len(buf) > 0 {
334+
m, e := c.Write(buf)
335+
n += m
336+
err = e
337+
}
338+
return n, err
330339
}
331340
}
332341

0 commit comments

Comments
 (0)