Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The adapter hangs in case the connection is dropped by a firewall after a period of inactivity #1

Open
ouadi opened this issue Apr 4, 2016 · 2 comments

Comments

@ouadi
Copy link

ouadi commented Apr 4, 2016

Hi,

I'm in a situation where my webapp hangs after a firewall drops the connection to the database, established by the adapter, after a certain period of inactivity.

A typical scenario is as follows:

  • Let's assume that we have a webapp that uses a database located behind a firewall
  • When the webapp is started, the adapter establishes a connection with the database
  • When clients connect to the webapp, it uses the adapter to persist/lookup the session into/from the database
  • Let's assume that there was no activity on the webapp for a period for which the firewall considers that the connection of the webapp to the database is inactive and it drops it
  • The first time a client with a session id sends a request to the webapp, it will try to lookup the session from the database using the received session id. It will fail with the error below and it will not reply. As such, it will give the impression that it is hanging.

The issue here is due to the fact that the 'pg' module is used to get a one new connection at the beginning and use it as far are the webapp is running.

A solution would be to ask the pg module to use a pool of connections with poolIdleTimeout less than the inactivity period of the firewall. As such, pg module will drop the connection first and recreate it when we ask it to give us a connection (a client).

The error is:

sails-pg-session#set -  Error: read ETIMEDOUT
    at exports._errnoException (util.js:874:11)
    at TCP.onread (net.js:544:26) { [Error: read ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'read' }
Error occurred in session middleware :: 'Error: read ETIMEDOUT\n    at exports._errnoException (util.js:874:11)\n    at TCP.onread (net.js:544:26)'
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
    at ServerResponse.res.setHeader (/home/saphir/ws/infra/saphir/ws/node_modules/SaphirNJS.bred.webapp/node_modules/sails/node_modules/express/node_modules/connect/lib/patch.js:134:22)
    at ServerResponse.res.set.res.header (/home/saphir/ws/infra/saphir/ws/node_modules/SaphirNJS.bred.webapp/node_modules/sails/node_modules/express/lib/response.js:595:10)
    at ServerResponse.res.send (/home/saphir/ws/infra/saphir/ws/node_modules/SaphirNJS.bred.webapp/node_modules/sails/node_modules/express/lib/response.js:151:12)
    at Immediate.<anonymous> (/home/saphir/ws/infra/saphir/ws/node_modules/SaphirNJS.bred.webapp/node_modules/sails/lib/hooks/http/middleware/defaults.js:56:24)
    at Immediate.immediate._onImmediate (timers.js:435:18)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
@slavafomin
Copy link

Hello! Is this module maintained?

@ouadi
Copy link
Author

ouadi commented Jul 30, 2016

It looks like it isn't. I have created a fork of it, patched this issue and created a PR. However, no reaction from the owner.

You can use my fork in case you found it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants