{"record":{"id":"baf77586f7fbf2a8","repo":"thanos-io/thanos","slug":"limit-d-overflows-int32","errorCode":null,"errorMessage":"limit %d overflows int32","messagePattern":"limit (.+?) overflows int32","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1748,"sourceCode":"\n\t// Append tenant matcher when tenancy is enabled.\n\tvar tenant string\n\tif qapi.enforceTenancy {\n\t\ttenant, err = tenancy.GetTenantFromHTTP(r, qapi.tenantHeader, qapi.defaultTenant, qapi.tenantCertField)\n\t\tif err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}, func() {}\n\t\t}\n\t\tif tenant != \"\" {\n\t\t\tmatchers = append(matchers, storepb.LabelMatcher{\n\t\t\t\tType:  storepb.LabelMatcher_EQ,\n\t\t\t\tName:  qapi.tenantLabel,\n\t\t\t\tValue: tenant,\n\t\t\t})\n\t\t}\n\t}\n\n\tif limit > math.MaxInt32 {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf(\"limit %d overflows int32\", limit)}, func() {}\n\t}\n\treq := &statuspb.TSDBStatisticsRequest{\n\t\tMatchers:                matchers,\n\t\tLimit:                   int32(limit),\n\t\tPartialResponseStrategy: ps,\n\t}\n\n\tvar stats map[string]*statuspb.TSDBStatisticsEntry\n\ttracing.DoInSpan(ctx, \"retrieve_tsdb_statistics\", func(ctx context.Context) {\n\t\tstats, warnings, err = qapi.status.TSDBStatistics(ctx, req)\n\t})\n\n\tif err != nil {\n\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Wrap(err, \"retrieving tsdb statistics\")}, func() {}\n\t}\n\n\tif tenant != \"\" {\n\t\tif stats[tenant] == nil {","sourceCodeStart":1730,"sourceCodeEnd":1766,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1730-L1766","documentation":"A range guard in the query API: the requested limit fits an int64 but exceeds math.MaxInt32, which is the widest limit the store API can carry in its protobuf fields. The request is rejected as bad data rather than silently truncating the limit.","triggerScenarios":"GET /api/v1/tsdb/status?limit=3000000000 (any value > 2147483647) reaching the tsdbStatus handler.","commonSituations":"Users attempting 'practically unlimited' limits with huge numbers; script-generated limits from config files; confusion with int64-range limits accepted by other endpoints.","solutions":["Use a limit <= 2147483647","Paginate queries instead of one huge limit"],"exampleFix":"// before\nGET /api/v1/tsdb/status?limit=3000000000\n// after\nGET /api/v1/tsdb/status?limit=1000000","handlingStrategy":"validation","validationCode":"function validTsdbLimit(n) { return Number.isInteger(n) && n >= 0 && n <= 2147483647; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap limits at math.MaxInt32 (2147483647).","Use a sane finite limit (e.g. 1e6) rather than a huge 'unlimited' value.","Reuse one client constant for the max allowed limit."],"tags":["limit","overflow","int32","tsdb-status"],"backgroundTag":"value-out-of-range","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}