{"record":{"id":"137b4f4f193e4ddb","repo":"ent/ent","slug":"gremlin-http-context-length-exceeds-limit","errorCode":null,"errorMessage":"gremlin/http: context length exceeds limit","messagePattern":"gremlin/http: context length exceeds limit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dialect/gremlin/http.go","lineNumber":75,"sourceCode":"\t{\n\t\treq, err := http.NewRequest(http.MethodPost, t.url, pr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"gremlin/http: creating http request: %w\", err)\n\t\t}\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\t\trsp, err := t.client.Do(req.WithContext(ctx))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"gremlin/http: posting http request: %w\", err)\n\t\t}\n\t\tdefer rsp.Body.Close()\n\n\t\tif rsp.StatusCode < http.StatusOK || rsp.StatusCode > http.StatusPartialContent {\n\t\t\tbody, _ := io.ReadAll(rsp.Body)\n\t\t\treturn nil, fmt.Errorf(\"gremlin/http: status=%q, body=%q\", rsp.Status, body)\n\t\t}\n\t\tif rsp.ContentLength > MaxResponseSize {\n\t\t\treturn nil, errors.New(\"gremlin/http: context length exceeds limit\")\n\t\t}\n\t\tbr = rsp.Body\n\t}\n\n\tvar rsp Response\n\tif err := graphson.NewDecoder(io.LimitReader(br, MaxResponseSize)).Decode(&rsp); err != nil {\n\t\treturn nil, fmt.Errorf(\"gremlin/http: decoding response: %w\", err)\n\t}\n\treturn &rsp, nil\n}\n","sourceCodeStart":57,"sourceCodeEnd":86,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/dialect/gremlin/http.go#L57-L86","documentation":"The HTTP transport caps response size at MaxResponseSize. If the server's Content-Length header exceeds that limit, the transport refuses to read the body and returns this error, protecting the client from unbounded memory usage.","triggerScenarios":"A Gremlin query returning a result set large enough that the response Content-Length exceeds MaxResponseSize.","commonSituations":"Queries without a limit() step returning huge vertex sets; bulk exports through the Gremlin HTTP endpoint; large property values (blobs) in results.","solutions":["Add `.limit(N)` (or a range) to the traversal to shrink the result set","Page through results using range/limit steps in a loop","Raise MaxResponseSize if your workload legitimately needs larger responses and you have the memory"],"exampleFix":"// before\ng.V().HasLabel(\"user\").Iterate(ctx)\n// after\ng.V().HasLabel(\"user\").Limit(1000).Iterate(ctx)","handlingStrategy":"try-catch","validationCode":"// use LimitReader yourself to pre-check feasibility, or check expected result size via count() query first\ng.V().HasLabel(\"user\").Count().Iterate(ctx) // verify size before fetching","typeGuard":null,"tryCatchPattern":"rsp, err := client.Traverse(ctx, t)\nif err != nil && strings.Contains(err.Error(), \"context length exceeds limit\") {\n  return retryWithLimit(ctx, t, 1000)\n}","preventionTips":["Always bound traversals with limit()/range steps","Count results before fetching large sets","Page through data instead of one large query","Size MaxResponseSize deliberately for your workload"],"tags":["gremlin","http","transport","response-size","memory"],"backgroundTag":"response-size-limit-exceeded","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}