mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	Move .LocalAddr() out of goroutine (#4281)
I don't have theory why this panics, but concurrency has something to do with it, so get the address before we call the goroutine. See #4271 Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
		
							
								
								
									
										3
									
								
								plugin/cache/handler.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								plugin/cache/handler.go
									
									
									
									
										vendored
									
									
								
							| @@ -49,11 +49,12 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) | |||||||
| 		servedStale.WithLabelValues(server).Inc() | 		servedStale.WithLabelValues(server).Inc() | ||||||
| 		// Adjust the time to get a 0 TTL in the reply built from a stale item. | 		// Adjust the time to get a 0 TTL in the reply built from a stale item. | ||||||
| 		now = now.Add(time.Duration(ttl) * time.Second) | 		now = now.Add(time.Duration(ttl) * time.Second) | ||||||
|  | 		addr := w.LocalAddr() // See https://github.com/coredns/coredns/issues/4271, unclear how, but pull this out of the goroutine, and get the address here. | ||||||
| 		go func() { | 		go func() { | ||||||
| 			if !do { | 			if !do { | ||||||
| 				setDo(rc) | 				setDo(rc) | ||||||
| 			} | 			} | ||||||
| 			crr := &ResponseWriter{Cache: c, state: state, server: server, prefetch: true, remoteAddr: w.LocalAddr(), do: do} | 			crr := &ResponseWriter{Cache: c, state: state, server: server, prefetch: true, remoteAddr: addr, do: do} | ||||||
| 			plugin.NextOrFailure(c.Name(), c.Next, ctx, crr, rc) | 			plugin.NextOrFailure(c.Name(), c.Next, ctx, crr, rc) | ||||||
| 		}() | 		}() | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user