3

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?

Nitin
  • 2,701
  • 2
  • 30
  • 60

2 Answers2

1

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.

getglad
  • 2,514
  • 3
  • 24
  • 47
  • I am using https://hub.docker.com/_/node/ .Can you help me where to put trap and entry point? – Nitin Jul 23 '18 at 13:38
  • If you aren't familiar with using Dockerfile manifests, I'd recommending reviewing this: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ – getglad Jul 23 '18 at 13:45
1

Multiple factors comes into picture here.

1 What is your minimum and maximum health percentage, if you have minimum health percentage 0, then while updating the service only your new task will be running and older task will be forcefully be stopped.

  1. What is the timing of your inflight request timing in alb, this decides how much time your old request will be processed before expiration.
Dharman
  • 30,962
  • 25
  • 85
  • 135