spring-cloud / spring-cloud/spring-cloud-gateway

Connection closed before response - maxHeaderSize configuration not applied in Spring Cloud Gateway (Netty)

Open
#3,960 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback-provided
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Even after explicitly configuring Netty’s maxHeaderSize and maxInitialLineLength in a Spring Cloud Gateway project, large HTTP headers still trigger connection closure errors such as:

reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response

It seems the configured limits are not being applied to the Netty HTTP server inside Spring Cloud Gateway.

What Was Tried

Added in configuration class:

httpServer.httpRequestDecoder(spec -> 
    spec.maxHeaderSize(32 * 1024).maxInitialLineLength(16 * 1024)
);

Tried:

server:
  max-http-header-size: 32768

Tried adding:

.maxHeaderSize(32 * 1024)

and

.maxInitialLineLength(16 * 1024)

on both client and server side.

Despite all of the above, the issue persists — large request headers (~>4KB) still cause premature connection closure.

The configured header size (e.g., 32KB) should be applied to the embedded Netty server and client, allowing the Gateway to handle larger headers gracefully.

Actual Behavior

Gateway still closes the connection when header size exceeds default Netty limit (8KB).

Debug logs show default Netty values, not the overridden ones.

Error stack shows:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is identified in the report. Start by reproducing the large-header request with the shown Netty and Spring Boot configurations, then trace where those settings are applied; done means the embedded Gateway server and client use the configured limits without premature closure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.