title: Connecting to AWS Fargate server behind an Application Load Balancer via Socket.io
body: <p>I have set up a server on AWS Fargate and I connect to the Application Load Balancer via Socket.io.</p>
  
  <p>I have enabled the access logs of the Application Load Balancer and the logs are as follows:</p>
  
  <pre><code>http 2018-12-25T04:00:15.787118Z app/EC2Co "GET http://ec2co.us-east-2.elb.amazonaws.com:28656/socket.io/?EIO=3&amp;transport=polling&amp;t=1545710415657-0 HTTP/1.1" "python-requests/2.20.0" - - arn:aws:elasticloadbalancing:us-east-2:735263141676:targetgroup/EC2Co-Defau-8X "Root=1-5c21ab4f-f26e11527cb2fa030ade3020" "-" "-" 0 2018-12-25T04:00:15.777000Z "forward" "-" "-"
  ws 2018-12-25T04:00:14.548103Z app/EC2Co "GET http://ec2co.us-east-2.elb.amazonaws.com:28656/socket.io/?EIO=3&amp;transport=websocket&amp;sid=ils820o21XTc_rlnAAAA HTTP/1.1" "python-requests/2.20.0" - - arn:aws:elasticloadbalancing:us-east-2:735263141676:targetgroup/EC2Co-Defau-8X "Root=1-5c21ab27-560b3f40746e96c087a97ec0" "-" "-" 0 2018-12-25T03:59:35.646000Z "forward" "-" "-"
  ws 2018-12-25T04:14:38.103181Z app/EC2Co "GET http://ec2co.us-east-2.elb.amazonaws.com:28656/socket.io/?EIO=3&amp;transport=websocket&amp;sid=lO2XYpIjTe_9p4s7AAAA HTTP/1.1" "python-requests/2.20.0" - - arn:aws:elasticloadbalancing:us-east-2:735263141676:targetgroup/EC2Co-Defau-8X "Root=1-5c21ab50-f024082cf6db65724f6384c0" "-" "-" 0 2018-12-25T04:00:16.360000Z "forward" "-" "-"
  http 2018-12-25T04:14:39.359703Z app/EC2Co "GET http://ec2co.us-east-2.elb.amazonaws.com:28656/socket.io/?EIO=3&amp;transport=polling&amp;t=1545711279222-0 HTTP/1.1" "python-requests/2.20.0" - - arn:aws:elasticloadbalancing:us-east-2:735263141676:targetgroup/EC2Co-Defau-8X "Root=1-5c21aeaf-8a69112ff7361e029ddedf81" "-" "-" 0 2018-12-25T04:14:39.344000Z "forward" "-" "-"
  </code></pre>
  
  <p>As you can see, the connection is upgrading to <code>websocket</code> connection correctly but downgrading to <code>polling</code>.</p>
  
  <p>I wanted to know if this is normal behaviour?</p>
  
  <p>The connection between the client and the Application Load Balancer keeps resetting approximately every 2 minutes, sometimes lesser than 2 minutes even if I send a <code>ping</code> to the load balancer every minute.</p>
  
  <p>Also, the health checks of the load balancer keep failing and none of the targets become healthy.</p>
  
  <p><a href="https://i.stack.imgur.com/nAmaj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nAmaj.png" alt="enter image description here"></a></p>
  
  <p>I have not explicitly defined the message <code>200 ok</code> in my client code for the load balancer to receive. Do I have to explicitly define the <code>200 ok</code> message? If yes, then what is the event that the load balancer sends during these health checks?</p>
  
  <p>The constant disconnect is causing some of the inputs from the client to the load balancer and in turn the AWS Fargate server to be lost.</p>
  
  <p>I am using <code>express</code> on my server. Below is the relevant code from app.js on the server:</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  var AWS = require ('aws-sdk');
  </code></pre>
  
  <p>Please note that the server code is in <code>Nodejs</code>, however the client code is in <code>Python</code>. Does that make a difference and causes disconnects?</p>
  
  <p>So, is this normal behaviour (seeing the logs above)? Or is there something I am missing?</p>
  
  <p>Also, how can I define the <code>200 ok</code> message to be sent to the load balancer when it does the health checks so that my targets become healthy?</p>
  
  <p>If there is any information I have missed and you require in order to answer this question, please comment below and I will edit the question to provide the required information.</p>
  
  <p>Thanks.</p>