0

I have a Koajs node app in a docker container on an EC2 instance. The app is behind an AWS Application Load Balancer.

The app simply takes a POSTed file and responds with a stream that the client can view events on.

So my server is doing the right thing (sending file data), and my client is doing the right thing (receiving file data and sending back progress), but the ALB is timing out. I don't understand why it's timing out. Both client and server are sending and receiving data to/from each other, so I would think that would qualify as keep alive traffic.

Here's the code that each is running. Client:

const request = require('request-promise');
const fs = require('fs');

const filePath = './1Gfile.txt';
const file = fs.createReadStream(filePath);

(async () => {
  // PUT File
  request.put({
    uri: `http://server/test`,
    formData: { file },
    headers: { Connection: 'keep-alive' },
    timeout: 200000,
  })
    .on('data', (data) => {
      const progressString = data.toString();
      console.log({ progressString });
    });
})();

Server:

const { Readable } = require('stream');                                                                                                                     
const Koa = require('koa');                                                                                                                                 
const router = require('koa-router')();                                                                                                                     

(async () => {                                                                                                                                              
  const app = module.exports = new Koa();                                                                                                                   

  router.get('/healthcheck', async (ctx) => {                                                                                                               
    ctx.status = 200;                                                                                                                                       
  });                                                                                                                                                       

  router.put('/test', test);                                                                                                                                

  async function test(ctx) {                                                                                                                                
    const read = new Readable({                                                                                                                             
      objectMode: true,                                                                                                                                     
      read() { },                                                                                                                                           
    });                                                                                                                                                     
    ctx.body = read;                                                                                                                                        

    let i = 1;                                                                                                                                              
    setInterval(() => {                                                                                                                                     
      read.push(`${process.hrtime()}, ${i}`);                                                                                                               
      ctx.res.write('a');                                                                                                                                   
      i++;                                                                                                                                                  
    }, 3000);                                                                                                                                               
  }                                                                                                                                                         

  app.use(router.routes());                                                                                                                                 
  app.use(router.allowedMethods());                                                                                                                         

  app.listen(3000, (err) => {                                                                                                                               
    if (err) throw err;                                                                                                                                     
    console.info(`App started on port 3000 with environment localhost`);                                                                                    
  });                                                                                                                                                       
})();   

Both server and client are logging the correct things, but the ALB just times out at whatever I set it's idle timeout to. Is there some trick to tell the ALB that traffic is really flowing?

Thanks so much for any light you can shed on it.

racecorp
  • 1
  • 1

1 Answers1

0

Just a quick guess, you need to enable keepAlive when using the request-promise. add forever: true in options. Try this:

request.put({
    uri: `http://server/test`,
    formData: { file },
    headers: { Connection: 'keep-alive' },
    timeout: 200000,
    forever: true,
  })

We have a similar issue about timeout when using request-promise-native. We fixed by adding this option. Hopfully it works out for you.

Herb
  • 305
  • 1
  • 7
  • Thanks for taking a look. I tried adding `timeout` and `forever`, but neither seemed to make a difference. – racecorp Sep 23 '19 at 18:53