Skip to content

Commit

Permalink
differentiate between reader and writer failures
Browse files Browse the repository at this point in the history
flow-indexer had a small bug introduced in 65ce12f
where it couldn't tell the difference between an error reading a log
file and an error writing the filtered response to the client.  To fix
this, use a bufio writer which lets you get the result of the write
operation via Flush().  If the Flush failed, it means there was an error
writing to the client and the request should be immediately aborted.
  • Loading branch information
JustinAzoff committed Feb 8, 2018
1 parent 02a1d0f commit f221c3c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion flowindexer/flowindexer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flowindexer

import (
"bufio"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -397,7 +398,12 @@ func (i *Indexer) Dump(query string, writer io.Writer) error {
}

for _, fn := range docs {
err = backend.FilterIPs(i.config.Backend, fn, query, writer)
bw := bufio.NewWriter(writer)
err = backend.FilterIPs(i.config.Backend, fn, query, bw)
if bw.Flush() != nil {
log.Printf("Error dumping %q: %q", fn, bw.Flush())
return bw.Flush()
}
if err != nil {
log.Printf("Error dumping %q: %q", fn, err)
}
Expand Down

0 comments on commit f221c3c

Please sign in to comment.