Feat/microservices configurable max buffer size #16262
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #16256
Currently,
MAX_BUFFER_SIZEis hard-coded inJsonSocketand cannot be configured. This causes issues when applications need to send larger messages between microservices over TCP, as the limit breaks the application when sending messages larger than 128MB (in characters).The
MAX_BUFFER_SIZEwas introduced in PR #14134 (v11) but was not made configurable, causing a regression for users who need to send larger messages.What is the new behavior?
The
maxBufferSizeoption is now configurable through the TCP microservice options:Server-side:
Client-side:
If
maxBufferSizeis not provided, the default value of 128MB (in characters) is used, maintaining backward compatibility.Does this PR introduce a breaking change?
This change is fully backward compatible. The
maxBufferSizeoption is optional, and when not provided, the existing default behavior is maintained.Other information
Changes Made
Core Changes:
packages/microservices/helpers/json-socket.ts- MademaxBufferSizeconfigurable via constructorpackages/microservices/interfaces/microservice-configuration.interface.ts- AddedmaxBufferSizeoption toTcpOptionspackages/microservices/interfaces/client-metadata.interface.ts- AddedmaxBufferSizeoption toTcpClientOptionspackages/microservices/client/client-tcp.ts- PassmaxBufferSizetoJsonSocketpackages/microservices/server/server-tcp.ts- PassmaxBufferSizetoJsonSocketTests Added:
packages/microservices/test/json-socket/max-buffer-size.spec.ts(14 tests)packages/microservices/test/client/client-tcp.spec.ts(3 tests)packages/microservices/test/server/server-tcp.spec.ts(3 tests)All tests pass successfully and backward compatibility is verified.
This PR addresses the issue reported in #16256 where users upgrading from NestJS v10 to v11 encountered a hard limit on TCP message sizes that broke their applications.