Fix for SNAT Exhaustion – Node.js Bots

This fix is to address time outs with Direct Line causing a 500:Connect ETIMEDOUT error under high loads –

  1. Use the AgentKeepAlive NPM module to ensure re-use of the SSL connections
  2. Tune the MaxSockets parameter of the AgentKeepAlive instance to be at least 160 to match the number of SNAT port.
const Agent = require('agentkeepalive');
 
const keepaliveAgent = new Agent({
  maxSockets: 160,
  maxFreeSockets: 10,
  timeout: 60000,
  freeSocketKeepAliveTimeout: 30000, // free socket keepalive for 30 seconds
});

Note: If you have set IISNode nodeProcessCountPerApplication = “0” to use all CPU’s for the Node process, then you will need to adjust the MaxSockets accordingly. For example, on a 4 CPU instance size (P4) you will have 4 Node Processes so MaxSockets will need to be set to 40 .

References:

Outbound connections in AzureĀ 

Azure SNAT

Thanks and happy coding!

The Bot Framework Team