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

AerospikeError: Not connected. after server restart #6

Closed
karlhiramoto opened this issue Mar 16, 2017 · 1 comment
Closed

AerospikeError: Not connected. after server restart #6

karlhiramoto opened this issue Mar 16, 2017 · 1 comment

Comments

@karlhiramoto
Copy link

It looks like if the connection between the server gets interrupted or the server restarts, the connection is never re-established.

To reproduce this

  1. Configure to just connect to a single aerosplike server
  2. read/write to session variables like normal on requests
  3. restart aerospike server.
  4. on next request, you will see this exception:
AerospikeError: Not connected.
    at Function.AerospikeError.fromASError (PROJECT_ROOT/node_modules/aerospike/lib/aerospike_error.js:113:10)
    at Client.DefaultCallbackHandler [as callbackHandler] (PROJECT_ROOT/node_modules/aerospike/lib/client.js:71:72)
    at nextTickCb (PROJECT_ROOT/node_modules/aerospike/lib/client.js:1471:10)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

To fix this you need to restart the node process which is very inconvenient. it would be much better if the client library detects this and reconnects.

@jhecking
Copy link
Member

Sorry for the late response. I was busy with other projects.

The client should automatically reconnect to the cluster once it comes back up. If the cluster goes down while your express app is running, you should see one of these two errors:

  • AerospikeError: Failed to connect
  • AerospikeError: Cluster is empty

You could get the error AerospikeError: Not connected if you are starting your express app while the Aerospike cluster is down. But I wasn't able to reproduce this error if the app is already running when the cluster goes down.

Here is the simple demo app I was using for testing:

$ cat express.js
const express = require('express')
const session = require('express-session')
const AerospikeStore = require('aerospike-session-store')(session)

var app = express()
app.use(session({
  secret: '123456789QWERTY',
  store: new AerospikeStore({
    namespace: 'express',
    set: 'session',
    ttl: 86400, // 1 day
    hosts: process.env.AEROSPIKE_HOSTS
  }),
  resave: false,
  saveUninitialized: false
}))
app.get('/', (req, res) => {
  var sess = req.session
  if (sess.views) {
    sess.views++
    res.setHeader('Content-Type', 'text/html')
    res.write('<p>views: ' + sess.views + '</p>')
    res.end()
  } else {
    console.log('initializing new session')
    sess.views = 1
    res.end('welcome to the session demo. refresh!')
  }
  console.log('views=', sess.views)
})
app.listen(3000, () => {
  console.log('Session store example listening at http://localhost:3000/')
})

I start this app, hit the root path a few times in the browser and then shut down the Aerospike server. When reloading the page, the error I see is AerospikeError: Failed to connect. But once I restart the server, the client automatically reconnects:

$ AEROSPIKE_HOSTS=192.168.33.10:3000 node ./express.js
Session store example listening at http://localhost:3000/
initializing new session
views= 1
views= 2
views= 3
views= 4
views= 5
AerospikeError: Failed to connect: BB9EB63B2005452 192.168.33.10:3000
    at Function.AerospikeError.fromASError (/Users/jhecking/aerospike/aerospike-session-store-expressjs/node_modules/aerospike/lib/aerospike_error.js:113:10)
    at Client.DefaultCallbackHandler [as callbackHandler] (/Users/jhecking/aerospike/aerospike-session-store-expressjs/node_modules/aerospike/lib/client.js:71:72)
    at getCb (/Users/jhecking/aerospike/aerospike-session-store-expressjs/node_modules/aerospike/lib/client.js:840:10)
AerospikeError: Failed to connect: BB9EB63B2005452 192.168.33.10:3000
    at Function.AerospikeError.fromASError (/Users/jhecking/aerospike/aerospike-session-store-expressjs/node_modules/aerospike/lib/aerospike_error.js:113:10)
    at Client.DefaultCallbackHandler [as callbackHandler] (/Users/jhecking/aerospike/aerospike-session-store-expressjs/node_modules/aerospike/lib/client.js:71:72)
    at getCb (/Users/jhecking/aerospike/aerospike-session-store-expressjs/node_modules/aerospike/lib/client.js:840:10)
views= 6
views= 7
views= 8

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