Skip to content

Limit REST write request size on dev/1.3 - #18461

Draft
HTHou wants to merge 1 commit into
dev/1.3from
codex/rest-request-limits-dev-1.3
Draft

Limit REST write request size on dev/1.3#18461
HTHou wants to merge 1 commit into
dev/1.3from
codex/rest-request-limits-dev-1.3

Conversation

@HTHou

@HTHou HTHou commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description

Backport the REST write request resource limits from #17481 to dev/1.3.

A crafted insertTablet or insertRecords request can contain an extremely large JSON body or a very large number of rows, columns, and values. Before this change, the REST layer deserialized and processed the payload without a bounded request-body or aggregate memory budget, which could exhaust DataNode heap under concurrent requests.

This change:

  • rejects an oversized request body before JSON deserialization with HTTP 413;
  • handles requests without a usable Content-Length by counting bytes while the entity stream is read;
  • limits total in-flight REST request-body bytes across concurrent requests and returns HTTP 503 when the budget is exhausted;
  • releases reservations when reading finishes, a request fails, or the response completes;
  • limits rows, columns, and values for REST v1/v2 write requests and returns HTTP 413;
  • supports hot reload for the REST runtime limits.

New configuration parameters:

  • rest_max_request_body_size_in_bytes=16777216
  • rest_max_total_concurrent_request_body_size_in_bytes=0
  • rest_max_insert_rows=100000
  • rest_max_insert_columns=1024
  • rest_max_insert_values=1000000

For rest_max_total_concurrent_request_body_size_in_bytes, 0 uses half of the free-memory share configured by datanode_memory_proportion (5% of maximum heap with the default ratio), matching the budget used by the newer branch's auto-resizing buffer memory control. Negative values disable the corresponding limit.

Compatibility

The dev/1.3 REST implementation is part of the DataNode module and supports tree-model REST v1/v2 only. This backport therefore adapts the fix to javax.ws.rs and Java 8 and does not include the newer table-model REST endpoints.

Tests

mvn spotless:apply -pl iotdb-core/datanode
mvn test -pl iotdb-core/datanode \
  -Dspotless.check.skip=true \
  -Dtest='RequestSizeLimitFilterTest,RequestValidationLimitTest,IoTDBRestServiceDescriptorTest' \
  -DfailIfNoTests=false \
  -Dsurefire.failIfNoSpecifiedTests=false

14 tests passed with no failures or errors.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.49077% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.55%. Comparing base (fb0b2d9) to head (e6f19a3).

Files with missing lines Patch % Lines
...b/protocol/rest/filter/RequestSizeLimitFilter.java 79.22% 16 Missing ⚠️
...ocol/rest/v2/handler/RequestValidationHandler.java 60.71% 11 Missing ⚠️
...ocol/rest/v1/handler/RequestValidationHandler.java 40.00% 9 Missing ⚠️
...b/db/protocol/rest/v2/impl/RestApiServiceImpl.java 0.00% 6 Missing ⚠️
.../db/protocol/rest/v1/handler/ExceptionHandler.java 0.00% 5 Missing ⚠️
.../db/protocol/rest/v2/handler/ExceptionHandler.java 0.00% 5 Missing ⚠️
...ocol/rest/filter/RestRequestBodyMemoryManager.java 92.50% 3 Missing ⚠️
...b/db/protocol/rest/v1/impl/RestApiServiceImpl.java 0.00% 3 Missing ⚠️
...iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java 95.74% 2 Missing ⚠️
.../db/protocol/rest/handler/RequestLimitChecker.java 94.11% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev/1.3   #18461      +/-   ##
=============================================
+ Coverage      44.46%   44.55%   +0.09%     
  Complexity       198      198              
=============================================
  Files           3641     3646       +5     
  Lines         246603   246865     +262     
  Branches       30284    30326      +42     
=============================================
+ Hits          109654   109999     +345     
+ Misses        136949   136866      -83     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant