From 18c666a1abb7a9225697f7e9dc0ddb91eb3f214e Mon Sep 17 00:00:00 2001 From: Terry Chan Date: Tue, 13 Jun 2023 23:44:48 +0800 Subject: [PATCH] Fix: aysnc exchange with new context (#2788) --- dns/resolver.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dns/resolver.go b/dns/resolver.go index 50e0c3d..75c907c 100644 --- a/dns/resolver.go +++ b/dns/resolver.go @@ -141,7 +141,11 @@ func (r *Resolver) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, e msg = cache.(*D.Msg).Copy() if expireTime.Before(now) { setMsgTTL(msg, uint32(1)) // Continue fetch - go r.exchangeWithoutCache(ctx, m) + go func() { + ctx, cancel := context.WithTimeout(context.Background(), resolver.DefaultDNSTimeout) + r.exchangeWithoutCache(ctx, m) + cancel() + }() } else { // updating TTL by subtracting common delta time from each DNS record updateMsgTTL(msg, uint32(time.Until(expireTime).Seconds()))