Skip to content

Commit ddf5f36

Browse files
committed
cmd/ejobs: fix unfortunate flag assignment typo and resulting discovered bug
https://go.dev/cl/679355 introduced the notion of 'max importers;' however, it made an error in flag assignment. This error resulted in discovering: ``` 500 Internal Server Error: analysisServer.handleEnqueue: moduleSpecsFromDB: pq: value "9223372036854775807" is out of range for type integer ``` Change-Id: I0de650fb332f9877a37180206ba78a92bdd1e8c7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/680936 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 2a8541e commit ddf5f36

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

cmd/ejobs/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ var commands = []command{
7070
"start a job",
7171
doStart,
7272
func(fs *flag.FlagSet) {
73-
fs.IntVar(&maxImporters, "min", -1,
73+
fs.IntVar(&minImporters, "min", -1,
7474
"run on modules with at least this many importers (<0: use server default of 10)")
75-
fs.IntVar(&minImporters, "max", -1,
76-
"run on modules with at most this many importers (<0: use server default of math.MaxInt)")
75+
fs.IntVar(&maxImporters, "max", -1,
76+
"run on modules with at most this many importers (<0: use server default of unlimited)")
7777
fs.StringVar(&moduleFile, "file", "",
7878
"file with modules to use: each line is MODULE_PATH VERSION NUM_IMPORTERS")
7979
fs.BoolVar(&noDeps, "nodeps", false, "do not download dependencies for modules")

internal/analysis/analysis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type EnqueueParams struct {
4444
Binary string // name of analysis binary to run
4545
Args string // command-line arguments to binary; split on whitespace
4646
Insecure bool // if true, run outside sandbox
47-
Min int // minimum import-by count for a module to be included
48-
Max int // maximum import-by count for a module to be included
47+
Min int32 // minimum import-by count for a module to be included
48+
Max int32 // maximum import-by count for a module to be included
4949
File string // path to file containing modules; if missing, use DB
5050
Suffix string // appended to task queue IDs to generate unique tasks
5151
User string // user initiating enqueue

internal/govulncheck/govulncheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const (
4848
type EnqueueQueryParams struct {
4949
Suffix string // appended to task queue IDs to generate unique tasks
5050
Mode string // type of analysis to run
51-
Min int // minimum import-by count for a module to be included
51+
Min int32 // minimum import-by count for a module to be included
5252
File string // path to file containing modules; if missing, use DB
5353
}
5454

internal/pkgsitedb/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func redactPassword(dbinfo string) string {
5252
// ModuleSpecs retrieves all modules that contain packages that are
5353
// imported by minImportedByCount or more packages.
5454
// It looks for the information in the search_documents table of the given pkgsite DB.
55-
func ModuleSpecs(ctx context.Context, db *sql.DB, minImports, maxImports int) (specs []scan.ModuleSpec, err error) {
55+
func ModuleSpecs(ctx context.Context, db *sql.DB, minImports, maxImports int32) (specs []scan.ModuleSpec, err error) {
5656
defer derrors.Wrap(&err, "moduleSpecsFromDB")
5757
query := `
5858
SELECT module_path, version, max(imported_by_count)

internal/pkgsitedb/db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestModuleSpecs(t *testing.T) {
5151
if err := db.PingContext(ctx); err != nil {
5252
t.Fatal(err)
5353
}
54-
got, err := ModuleSpecs(ctx, db, 1000, math.MaxInt)
54+
got, err := ModuleSpecs(ctx, db, 1000, math.MaxInt32)
5555
if err != nil {
5656
t.Fatal(err)
5757
}

internal/scan/parse.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ModuleSpec struct {
3535
ImportedBy int
3636
}
3737

38-
func ParseCorpusFile(filename string, minImports, maxImports int) (ms []ModuleSpec, err error) {
38+
func ParseCorpusFile(filename string, minImports, maxImports int32) (ms []ModuleSpec, err error) {
3939
defer derrors.Wrap(&err, "ParseCorpusFile(%q)", filename)
4040
lines, err := ReadFileLines(filename)
4141
if err != nil {
@@ -56,12 +56,12 @@ func ParseCorpusFile(filename string, minImports, maxImports int) (ms []ModuleSp
5656
default:
5757
return nil, fmt.Errorf("wrong number of fields on line %q", line)
5858
}
59-
n, err := strconv.Atoi(imps)
59+
n, err := strconv.ParseInt(imps, 10, 32)
6060
if err != nil {
61-
return nil, fmt.Errorf("%v on line %q", err, line)
61+
return nil, fmt.Errorf("number of imports: invalid integer %q", imps)
6262
}
63-
if minImports <= n && n <= maxImports {
64-
ms = append(ms, ModuleSpec{Path: path, Version: vers, ImportedBy: n})
63+
if minImports <= int32(n) && int32(n) <= maxImports {
64+
ms = append(ms, ModuleSpec{Path: path, Version: vers, ImportedBy: int(n)})
6565
}
6666
}
6767
return ms, nil

internal/scan/parse_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestModuleURLPathError(t *testing.T) {
101101

102102
func TestParseCorpusFile(t *testing.T) {
103103
const file = "testdata/modules.txt"
104-
got, err := ParseCorpusFile(file, 1, math.MaxInt)
104+
got, err := ParseCorpusFile(file, 1, math.MaxInt32)
105105
if err != nil {
106106
t.Fatal(err)
107107
}
@@ -115,7 +115,7 @@ func TestParseCorpusFile(t *testing.T) {
115115
t.Errorf("\n got %v\nwant %v", got, want)
116116
}
117117

118-
got, err = ParseCorpusFile(file, 10, math.MaxInt)
118+
got, err = ParseCorpusFile(file, 10, math.MaxInt32)
119119
if err != nil {
120120
t.Fatal(err)
121121
}

internal/worker/enqueue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919

2020
const (
2121
defaultMinImportedByCount = 10
22-
defaultMaxImportedByCount = math.MaxInt
22+
defaultMaxImportedByCount = math.MaxInt32
2323
)
2424

25-
func readModules(ctx context.Context, cfg *config.Config, file string, minImports, maxImports int) ([]scan.ModuleSpec, error) {
25+
func readModules(ctx context.Context, cfg *config.Config, file string, minImports, maxImports int32) ([]scan.ModuleSpec, error) {
2626
if file != "" {
2727
log.Infof(ctx, "reading modules from file %s", file)
2828
return scan.ParseCorpusFile(file, minImports, maxImports)
@@ -31,7 +31,7 @@ func readModules(ctx context.Context, cfg *config.Config, file string, minImport
3131
return readFromDB(ctx, cfg, minImports, maxImports)
3232
}
3333

34-
func readFromDB(ctx context.Context, cfg *config.Config, minImports, maxImports int) ([]scan.ModuleSpec, error) {
34+
func readFromDB(ctx context.Context, cfg *config.Config, minImports, maxImports int32) ([]scan.ModuleSpec, error) {
3535
db, err := pkgsitedb.Open(ctx, cfg)
3636
if err != nil {
3737
return nil, err

internal/worker/govulncheck_enqueue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func createGovulncheckQueueTasks(ctx context.Context, cfg *config.Config, params
8181
)
8282
for _, mode := range modes {
8383
if modspecs == nil {
84-
modspecs, err = readModules(ctx, cfg, params.File, params.Min, math.MaxInt)
84+
modspecs, err = readModules(ctx, cfg, params.File, params.Min, math.MaxInt32)
8585
if err != nil {
8686
return nil, err
8787
}

0 commit comments

Comments
 (0)