Spring Gateway — Connection prematurely closed

Posted on

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 :

Leave a Reply

Your email address will not be published. Required fields are marked *