cayleygraph/cayley · error

request data is too large

Error message

request data is too large

What it means

ServeNodeDelete reads the DELETE request body through an io.LimitReader capped at a configured limit. If the body fills that limit entirely (len(data) == limit), the payload is at or over the cap, so the API refuses it with a 400 rather than parsing an oversized value. This protects the server from unbounded bodies used to delete large values.

Source

Thrown at server/http/api_v2.go:324

func (api *APIv2) ServeNodeDelete(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()
	if api.ro {
		jsonResponse(w, http.StatusForbidden, errors.New("database is read-only"))
		return
	}
	format := getFormat(r, "", hdrContentType)
	if format == nil || format.UnmarshalValue == nil {
		jsonResponse(w, http.StatusBadRequest, fmt.Errorf("format is not supported for reading nodes"))
		return
	}
	const limit = 128*1024 + 1
	rd := io.LimitReader(r.Body, limit)
	data, err := ioutil.ReadAll(rd)
	if err != nil {
		jsonResponse(w, http.StatusBadRequest, err)
		return
	} else if len(data) == limit {
		jsonResponse(w, http.StatusBadRequest, fmt.Errorf("request data is too large"))
		return
	}
	v, err := format.UnmarshalValue(data)
	if err != nil {
		jsonResponse(w, http.StatusBadRequest, err)
		return
	} else if v == nil {
		jsonResponse(w, http.StatusBadRequest, fmt.Errorf("cannot remove nil value"))
		return
	}
	h, err := api.handleForRequest(r)
	if err != nil {
		jsonResponse(w, http.StatusBadRequest, err)
		return
	}
	err = h.RemoveNode(v)
	if err != nil {
		jsonResponse(w, http.StatusInternalServerError, err)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Split the delete payload into smaller batches so each request stays under the limit.
  2. Increase the server's max request size configuration and restart Cayley.
  3. Inspect the payload for accidental inflation (encoding, duplicates) with a smaller test request.

Example fix

// before: one huge delete request
curl -X POST -d @all-nodes.json http://localhost:64210/api/v2/node/delete
// after: split into batches
curl -X POST -d @nodes-batch-1.json http://localhost:64210/api/v2/node/delete
curl -X POST -d @nodes-batch-2.json http://localhost:64210/api/v2/node/delete
Defensive patterns

Strategy: validation

Validate before calling

body, _ := json.Marshal(payload)
serverLimit := 4 << 20 // must match the server's max request size
if len(body) >= serverLimit {
    return errors.New("delete payload exceeds server request-size limit; split into batches")
}

Prevention

When it happens

Trigger: Posting to /api/v2/node/delete with a request body whose serialized size equals or exceeds the server's configured max request size (the limit passed to io.LimitReader).

Common situations: Bulk-deletion scripts batching many nodes into one request; deployments started with a small max-request-size setting and later given larger workloads; clients accidentally inflating payloads (base64, duplicated entries).

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/3bf73739af1bdc7f. Report an issue: GitHub.