mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	don't spam Travis + valid dnstap payload
This commit is contained in:
		@@ -3,6 +3,7 @@ package dnstapio
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	tap "github.com/dnstap/golang-dnstap"
 | 
			
		||||
	"github.com/golang/protobuf/proto"
 | 
			
		||||
@@ -10,6 +11,7 @@ import (
 | 
			
		||||
 | 
			
		||||
// DnstapIO wraps the dnstap I/O routine.
 | 
			
		||||
type DnstapIO struct {
 | 
			
		||||
	iolog  io.Writer
 | 
			
		||||
	writer io.WriteCloser
 | 
			
		||||
	queue  chan tap.Dnstap
 | 
			
		||||
	stop   chan bool
 | 
			
		||||
@@ -25,7 +27,7 @@ type Protocol interface {
 | 
			
		||||
 | 
			
		||||
// New dnstap I/O routine from Protocol.
 | 
			
		||||
func New(w Protocol) *DnstapIO {
 | 
			
		||||
	dio := DnstapIO{}
 | 
			
		||||
	dio := DnstapIO{iolog: os.Stdout}
 | 
			
		||||
	dio.writer = w
 | 
			
		||||
	dio.queue = make(chan tap.Dnstap, 10)
 | 
			
		||||
	dio.stop = make(chan bool)
 | 
			
		||||
@@ -38,7 +40,7 @@ func (dio *DnstapIO) Dnstap(payload tap.Dnstap) {
 | 
			
		||||
	select {
 | 
			
		||||
	case dio.queue <- payload:
 | 
			
		||||
	default:
 | 
			
		||||
		fmt.Println("[WARN] Dnstap payload dropped.")
 | 
			
		||||
		fmt.Fprintln(dio.iolog, "[WARN] Dnstap payload dropped.")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -50,7 +52,7 @@ func (dio *DnstapIO) serve() {
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				dio.writer.Write(frame)
 | 
			
		||||
			} else {
 | 
			
		||||
				fmt.Println("[ERROR] Invalid dnstap payload dropped.")
 | 
			
		||||
				fmt.Fprintf(dio.iolog, "[ERROR] Invalid dnstap payload dropped: %s\n", err)
 | 
			
		||||
			}
 | 
			
		||||
		case <-dio.stop:
 | 
			
		||||
			close(dio.queue)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package dnstapio
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -26,6 +27,7 @@ func (b buf) Close() error {
 | 
			
		||||
func TestRace(t *testing.T) {
 | 
			
		||||
	b := buf{&bytes.Buffer{}, 100 * time.Millisecond}
 | 
			
		||||
	dio := New(b)
 | 
			
		||||
	dio.iolog = ioutil.Discard // don't flood Travis
 | 
			
		||||
	wg := &sync.WaitGroup{}
 | 
			
		||||
	wg.Add(10)
 | 
			
		||||
	for i := 0; i < 10; i++ {
 | 
			
		||||
@@ -38,7 +40,8 @@ func TestRace(t *testing.T) {
 | 
			
		||||
					return
 | 
			
		||||
				default:
 | 
			
		||||
					time.Sleep(50 * time.Millisecond)
 | 
			
		||||
					dio.Dnstap(tap.Dnstap{})
 | 
			
		||||
					t := tap.Dnstap_MESSAGE
 | 
			
		||||
					dio.Dnstap(tap.Dnstap{Type: &t})
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user