From 289a14308963bf2cc897739ed0e2905eba5210b2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 29 Nov 2019 10:14:46 +0100 Subject: 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. --- syz-hub/state/state.go | 31 ++++++++++++++----------------- 1 file 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] -} -- cgit mrf-deployment