Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.27] Fix broken pipe error when listing temp IP sets #9079

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions felix/ipsets/ipsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ func (s *IPSets) runIPSetList(arg string, parsingFunc func(*bufio.Scanner) error
// Use a scanner to chunk the input into lines.
scanner := bufio.NewScanner(out)
parsingErr := parsingFunc(scanner)
if parsingErr == nil {
// In case the parsingFunc stopped early, drain stdout fully.
for scanner.Scan() {
}
parsingErr = scanner.Err()
}
closeErr := out.Close()
err = cmd.Wait()
logCxt := s.logCxt.WithField("stderr", stderr.String())
Expand Down Expand Up @@ -807,6 +813,13 @@ func (s *IPSets) writeUpdates(setName string, w io.Writer) (err error) {
// If the metadata needs to change then we have to write to a temporary IP
// set and swap it into place.
needTempIPSet := dpExists && dpMeta != desiredMeta
if needTempIPSet {
log.WithFields(log.Fields{
"desired": desiredMeta,
"dataplane": dpMeta,
"setName": setName,
}).Info("IP set metadata change, need to use a temporary IP set.")
}
// If the IP set doesn't exist yet, we need to create it.
needCreate := !dpExists

Expand Down
29 changes: 20 additions & 9 deletions felix/ipsets/utils_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,22 @@ func (c *listCmd) main() {
defer func() {
log.WithField("result", result).Info("list command main exiting")
if c.Stdout != nil {
c.Stdout.Close()
err := c.Stdout.Close()
if err != nil && result == nil {
result = err
}
}
c.resultC <- result
}()

writef := func(s string, args ...any) {
_, err := fmt.Fprintf(c.Stdout, s, args...)
if err != nil && result == nil {
log.WithError(err).Info("List command hit write error.")
result = err
}
}

if c.Dataplane.FailAllLists {
log.Info("Simulating persistent failure of ipset list")
result = permanentFailure
Expand Down Expand Up @@ -715,7 +726,7 @@ func (c *listCmd) main() {
result = fmt.Errorf("ipset %v does not exists", c.SetName)
return
}
fmt.Fprintf(c.Stdout, "Name: %s\n", c.SetName)
writef("Name: %s\n", c.SetName)
meta, ok := c.Dataplane.IPSetMetadata[c.SetName]
if !ok {
// Default metadata for IP sets created by tests.
Expand All @@ -726,18 +737,18 @@ func (c *listCmd) main() {
MaxSize: 1234,
}
}
fmt.Fprintf(c.Stdout, "Type: %s\n", meta.Type)
writef("Type: %s\n", meta.Type)
if meta.Type == IPSetTypeBitmapPort {
fmt.Fprintf(c.Stdout, "Header: family %s range %d-%d\n", meta.Family, meta.RangeMin, meta.RangeMax)
writef("Header: family %s range %d-%d\n", meta.Family, meta.RangeMin, meta.RangeMax)
} else if meta.Type == "unknown:type" {
fmt.Fprintf(c.Stdout, "Header: floop\n")
writef("Header: floop\n")
} else {
fmt.Fprintf(c.Stdout, "Header: family %s hashsize 1024 maxelem %d\n", meta.Family, meta.MaxSize)
writef("Header: family %s hashsize 1024 maxelem %d\n", meta.Family, meta.MaxSize)
}
fmt.Fprint(c.Stdout, "Field: foobar\n") // Dummy field, should get ignored.
fmt.Fprint(c.Stdout, "Members:\n")
writef("Field: foobar\n") // Dummy field, should get ignored.
writef("Members:\n")
members.Iter(func(member string) error {
fmt.Fprintf(c.Stdout, "%s\n", member)
writef("%s\n", member)
return nil
})
}