Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS ECS websocket connection draining while updating ECS service

I am using AWS ECS to run chat application written in nodejs with help of socket.io.

I used AWS Application Load Balancer as front and created one target group, target group contains AWS ECS service.

Now, let say I create 1 service with my container(using task definition) and added in the target group and the user starts connecting to my AWS ECS service using websocket.

My question is, If I update my service with new task definition, Will AWS ECS wait for older websocket connection to gracefully disconnect or it will forcefully disconnect older websocket connection with old service?

like image 885
Nitin Avatar asked Oct 25 '25 00:10

Nitin


1 Answers

Your websocket connections would be out of bounds activity for ECS - it has no visibility into it. So ECS won't help you here, but...

When you update the service, it would be equivalent to sending a docker stop command. This means that a stop signal is sent.

According to the ECS docs:

When StopTask is called on a task, the equivalent of docker stop is issued to the containers running in the task. This results in a SIGTERM and a default 30-second timeout, after which SIGKILL is sent and the containers are forcibly stopped. If the container handles the SIGTERM gracefully and exits within 30 seconds from receiving it, no SIGKILL is sent.

You should be able to set a trap in your entrypoint script that could execute some sort of graceful handoff process.

So something along the lines of:

#!/bin/bash
... other code...
function handleShutdownFoo {
  # do something...
}
trap handleShutdownFoo SIGTERM
... more code ...

For more information on containerizing a nodejs app, review this guide from the Node team.

like image 147
getglad Avatar answered Oct 27 '25 14:10

getglad