The streamer read the feed with a bufio.Scanner at its default limit of 64 KiB per line, so a longer line ended the connection and the updates sent while it reconnected were lost. The scanner now accepts lines up to 1 MiB (maxLineSize), well above an extended BGP message written out as the feed writes it. Model: opus-5-5
This commit was merged in pull request #89.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -396,6 +397,35 @@ func TestStreamNotDroppedWhileLinesArrive(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStreamReadsLongLine has the server send one UPDATE line of about
|
||||
// 200 KiB, padded with raw hex the way RIS Live writes an extended BGP
|
||||
// message, and then end the response. The line is longer than a
|
||||
// bufio.Scanner reads by default. The streamer must hand the message to the
|
||||
// handler's queue and read on until the server ends the stream, instead of
|
||||
// dropping the connection at the long line.
|
||||
func TestStreamReadsLongLine(t *testing.T) {
|
||||
const rawHexLength = 200 * bytesPerKB
|
||||
longLine := `{"type":"ris_message","data":{"type":"UPDATE","peer":"192.0.2.1",` +
|
||||
`"peer_asn":"64496","timestamp":1700000000,"raw":"` +
|
||||
strings.Repeat("0", rawHexLength) + `"}}` + "\n"
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = io.WriteString(w, longLine)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
s := New(logger.New(), metrics.New())
|
||||
s.url = srv.URL
|
||||
s.RegisterHandler(updateHandler{})
|
||||
|
||||
if err := s.stream(context.Background()); !errors.Is(err, errStreamEnded) {
|
||||
t.Fatalf("stream returned %v, want %v", err, errStreamEnded)
|
||||
}
|
||||
|
||||
if queued := len(s.handlers[0].queue); queued != 1 {
|
||||
t.Errorf("handler queue holds %d messages, want 1", queued)
|
||||
}
|
||||
}
|
||||
|
||||
// checkReconnect runs a streamer against a fake RIS Live server. The first
|
||||
// response is served by firstResponse; every later one carries one UPDATE
|
||||
// line and then stays open. The streamer must come back for a second
|
||||
|
||||
Reference in New Issue
Block a user