From 27637e0ed497dbd1e862750b14f9a5c0be368f15 Mon Sep 17 00:00:00 2001 From: ignoramous Date: Tue, 2 Jul 2024 04:15:48 +0530 Subject: [PATCH] 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. --- Android/app/src/go/intra/split/retrier.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Android/app/src/go/intra/split/retrier.go b/Android/app/src/go/intra/split/retrier.go index c9c3a8ed..dbeba65e 100644 --- a/Android/app/src/go/intra/split/retrier.go +++ b/Android/app/src/go/intra/split/retrier.go @@ -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 @@ -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 } }