DEV Community

Cover image for Spring Gateway — Connection prematurely closed

Spring Gateway — Connection prematurely closed

Maxime Guilbert
Just a dev who touches a lot of things and wants to share his experiences. (or just want to note somewhere things to don't forget)
Updated on ・1 min read

During your working on a Spring Gateway, you can have this kind of issue which seems to come from out of nowhere:

 reactor.netty.http.client.PrematureCloseException: Connection prematurely closed DURING response
Enter fullscreen mode Exit fullscreen mode

After reviewing a lot of GitHub or StackOverflow pages, the only things I saw to correct it was to update the netty library (In the case of Spring Gateway, update the spring library because it embeds netty.) or to update some configs.

But maybe it won’t help you that much. If you continue to have this issue, check your infrastructure.

In our case, our load balancers were the problem.

For some reason, we changed our CLB (Classic Load Balancers) for NLB (Network Load Balancer) in AWS. But the default configuration wasn’t correct for our usage. So we randomly had this “Connection prematurely closed” error. Then, when we go back to CLB, it worked well.

Currently, I didn’t take the time to explore why this is happening with NLB, but I really want to share this point that I never saw anywhere else. I hope it will help you!

Links to PrematureCloseException issues in GitHub :

Discussion (0)