@@ -83,6 +83,11 @@ func (w Wayback) Names(ctx context.Context, domain string) ([]string, error) {
8383 body := & io.LimitedReader {R : resp .Body , N : waybackMaxBody }
8484 names , lines , err := hostNames (body , domain )
8585 if err != nil {
86+ if len (names ) > 0 {
87+ // The body read failed midway (a timeout, a reset connection):
88+ // keep the names read before the cut (#409).
89+ return names , & Truncated {Source : "wayback" , Why : fmt .Sprintf ("the answer was cut off: %v" , err )}
90+ }
8691 return nil , fmt .Errorf ("wayback machine lookup: reading %s's answer: %w" , resp .Request .URL .Host , err )
8792 }
8893 switch {
@@ -99,16 +104,19 @@ func (w Wayback) Names(ctx context.Context, domain string) ([]string, error) {
99104const waybackMaxLine = 1 << 20
100105
101106// hostNames reads one archived URL per line and returns the hosts under
102- // domain, relative to it, and how many lines it read.
107+ // domain, relative to it, and how many lines it read. On a read error it
108+ // returns the hosts read before it, with the error (#409).
103109func hostNames (r io.Reader , domain string ) ([]string , int , error ) {
104110 domain = strings .ToLower (strings .TrimSuffix (domain , "." ))
105111 set := map [string ]bool {}
106112 br := bufio .NewReaderSize (r , 64 << 10 )
107113 lines := 0
114+ var readErr error
108115 for {
109116 raw , tooLong , err := readURLLine (br )
110117 if err != nil && ! errors .Is (err , io .EOF ) {
111- return nil , lines , err
118+ readErr = err // the partial line before the error is dropped
119+ break
112120 }
113121 line := strings .TrimSpace (string (raw ))
114122 if tooLong {
@@ -126,7 +134,7 @@ func hostNames(r io.Reader, domain string) ([]string, int, error) {
126134 out = append (out , n )
127135 }
128136 sort .Strings (out )
129- return out , lines , nil
137+ return out , lines , readErr
130138}
131139
132140// readURLLine reads one line, without its newline. A line over
0 commit comments