From f20baf28be3e18cef0a4695d25db202dbc124300 Mon Sep 17 00:00:00 2001
From: Irine Sistiana <49315432+IrineSistiana@users.noreply.github.com>
Date: Wed, 11 Dec 2024 20:51:12 +0800
Subject: [PATCH 2/2] upstream: resend udp package every 1s

---
 pkg/upstream/transport/conn_traditional.go | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

--- a/pkg/upstream/transport/conn_traditional.go
+++ b/pkg/upstream/transport/conn_traditional.go
@@ -124,9 +124,24 @@ func (dc *TraditionalDnsConn) exchange(c
 		dc.c.SetReadDeadline(time.Now().Add(waitingReplyTimeout))
 	}
 
+	var resend <-chan time.Time
+	if !dc.isTcp {
+		ticker := time.NewTicker(time.Second)
+		resend = ticker.C
+		defer ticker.Stop()
+	}
+
+wait:
 	select {
 	case <-ctx.Done():
 		return nil, context.Cause(ctx)
+	case <-resend:
+		err := dc.writeQuery(q, assignedQid)
+		if err != nil {
+			dc.CloseWithErr(fmt.Errorf("write err, %w", err))
+			return nil, err
+		}
+		goto wait
 	case r := <-respChan:
 		orgId := binary.BigEndian.Uint16(q)
 		binary.BigEndian.PutUint16(*r, orgId)
