aboutsummaryrefslogtreecommitdiffstats
path: root/syz-hub/state
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-11-29 10:14:46 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-11-29 10:46:26 +0100
commit289a14308963bf2cc897739ed0e2905eba5210b2 (patch)
tree7fab289755901850aed7380ef119cf0691bb09f0 /syz-hub/state
parentaac51b70cdffdf58901684563119bd1c01751ecc (diff)
syz-hub: cap total number of programs sent to a manager
If we have way too many programs to send (more than 100000), cap total number to 100000 and give up sending all. Otherwise new managers will never chew all this on a busy hub.
Diffstat (limited to 'syz-hub/state')
-rw-r--r--syz-hub/state/state.go31
1 files changed, 14 insertions, 17 deletions
diff --git a/syz-hub/state/state.go b/syz-hub/state/state.go
index 7ccdf1827..a8a1b36ea 100644
--- a/syz-hub/state/state.go
+++ b/syz-hub/state/state.go
@@ -288,10 +288,21 @@ func (st *State) pendingInputs(mgr *Manager) ([][]byte, int, error) {
}
maxSeq := st.corpusSeq
more := 0
- // Send at most that many records (rounded up to next seq number).
- const maxRecords = 100
+ const (
+ // Send at most that many records (rounded up to next seq number).
+ maxRecords = 100
+ // If we have way too many records to send (more than capRecords),
+ // cap total number to capRecords and give up sending all.
+ // Otherwise new managers will never chew all this on a busy hub.
+ capRecords = 100000
+ )
if len(records) > maxRecords {
- sort.Sort(recordSeqSorter(records))
+ sort.Slice(records, func(i, j int) bool {
+ return records[i].Seq < records[j].Seq
+ })
+ if len(records) > capRecords {
+ records = records[len(records)-capRecords:]
+ }
pos := maxRecords
maxSeq = records[pos].Seq
for pos+1 < len(records) && records[pos+1].Seq == maxSeq {
@@ -380,17 +391,3 @@ func loadSeqFile(filename string) uint64 {
seq, _ := strconv.ParseUint(string(str), 10, 64)
return seq
}
-
-type recordSeqSorter []db.Record
-
-func (a recordSeqSorter) Len() int {
- return len(a)
-}
-
-func (a recordSeqSorter) Less(i, j int) bool {
- return a[i].Seq < a[j].Seq
-}
-
-func (a recordSeqSorter) Swap(i, j int) {
- a[i], a[j] = a[j], a[i]
-}