Skip to content

Getting Error: socket hang up on long requests in my AWS architecture

0

Hi!

I'm getting the next error Error: socket hang up when I call an endpoint that takes some time (my backend is built in Java with SpringBoot). In my localhost it works even if it takes time but on the my AWS environment even if my alb has a 10 minutes timeout and my tasks have the right amount of memory I get that error when waiting for the response.

There is a way to fix this? Or should rethink and change maybe that endpoint internally so it uses another approach to do the logic and be more efficient?

Thanks!

2 Answers
1
Accepted Answer

Hi,

This kind of errors most frequently come from one or several sec groups on the chain (vpc -> ALB -> cluster -> task) not properly configured to let your trafic reach the container.

So, check those sec groups to see if all allow the kind of inbound traffic that you wish.

Reachability Analyzer may help you in finding the faulty sec groups: see https://docs.aws.amazon.com/vpc/latest/reachability/what-is-reachability-analyzer.html

Best,

Didier

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • I see, thanks Didier! I will check it out

  • Hi Cao95, you're very welcome!

0

The "socket hang up" error you're experiencing in your AWS environment for long-running requests is likely related to connection timeouts. This issue can occur due to various reasons, even if your Application Load Balancer (ALB) has a 10-minute timeout configured. Here are some potential causes and solutions to consider:

  1. Client-side timeout: Your client application might have a default timeout that's shorter than the server-side processing time. Ensure that your client-side timeout settings are appropriately configured to match the expected response time.

  2. Intermediate network components: There could be firewalls, proxies, or other network components between your client and the AWS environment that are closing idle connections. These components may have their own timeout settings that are shorter than your ALB's configuration.

  3. Connection inactivity: For long-running operations, if there's no data transfer between the client and server for an extended period, intermediate network components might close the connection, thinking it's inactive.

  4. Server-side issues: Your Java Spring Boot application might be encountering issues that prevent it from responding within the expected timeframe.

To address this problem, consider the following approaches:

  1. Implement a keep-alive mechanism: For long-running operations, periodically send small chunks of data or progress updates to keep the connection active.

  2. Use asynchronous processing: Instead of waiting for the entire operation to complete, consider implementing an asynchronous approach. Return an immediate response with a job ID or status URL, and allow the client to poll for updates or use websockets for real-time progress.

  3. Optimize your backend: Review your Java Spring Boot application for potential bottlenecks or inefficiencies that might be causing the long processing times. Consider breaking down the operation into smaller, more manageable chunks.

  4. Implement retry logic: On the client-side, implement exponential backoff and retry mechanisms to handle timeouts gracefully.

  5. Adjust timeout settings: Review and adjust timeout settings across your entire stack, including the client, ALB, and any intermediate network components.

  6. Enable connection keep-alive: Ensure that HTTP keep-alive is enabled on both the client and server sides to maintain persistent connections.

While optimizing your endpoint for efficiency is always a good practice, it's also important to implement proper error handling and timeout management for long-running operations. A combination of backend optimization and implementing a more resilient communication pattern (like asynchronous processing) may be the best approach for your use case.
Sources
Troubleshooting FAQs - AWS SDK for Java 2.x
Troubleshoot OpenSearch Service timeout issues | AWS re:Post

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.