Tuesday 23 May 2017

How to limit the number of connections in expressjs

I have a tiny internal express app that I want only a single user to be able to access at any given time.

The relevant code is as follows:

var express        =  require('express')
  , app            =  express()
  , server         = require('http').createServer(app)
  , auth           = require('./js/auth')
  ;

...
// Just a bunch of application code itself
app
  .use
  .use
  .post
...

server.maxConnections = 1;

I have used the information from these answers and docs:

Limit maximum connections to NodeJS Server

How to limit my node.js client connections to 2?

https://nodejs.org/api/all.html#net_server_maxconnections

But none of these seem to work. When I start my application on the localhost:port and try to access the app with chrome and firefox I can still open a bunch of connections:

lsof -i :myport

FF NODE NAME/OFF NODE NAME
firefox     294 myuser   82u  IPv6 0xc18dd6d75deac611      0t0  TCP localhost:52237->localhost:hbci (ESTABLISHED)
firefox     294 myuser   92u  IPv6 0xc18dd6d75e3adb91      0t0  TCP localhost:52241->localhost:hbci (ESTABLISHED)
firefox     294 myuser   96u  IPv6 0xc18dd6d75e3b20d1      0t0  TCP localhost:52242->localhost:hbci (ESTABLISHED)
firefox     294 myuser   99u  IPv6 0xc18dd6d75a52a611      0t0  TCP localhost:52239->localhost:hbci (ESTABLISHED)
Google      314 myuser   86u  IPv6 0xc18dd6d75a52b611      0t0  TCP localhost:52225->localhost:hbci (ESTABLISHED)
Google      314 myuser  113u  IPv6 0xc18dd6d75a52b0d1      0t0  TCP localhost:52227->localhost:hbci (ESTABLISHED)

What am I doing wrong?



via user3081519

No comments:

Post a Comment