I'm using RethinkDB together with hapi.js in Node.js. My main application passes an open connection to a hapi.js plugin. Using the connection inside the main-script works fine, but running something inside the plugin throws the following error:
Unhandled rejection ReqlDriverError: First argument to `run` must be an open connection.
I tried to figure out if the connection gets closed, but non of the added listeners fire.
connection.addListener('connect', () => { console.log('!!connect') })
connection.addListener('close', () => { console.log('!!closed') })
connection.addListener('timeout', () => { console.log('!!timeout') })
connection.addListener('error', () => { console.log('!!error') })
I can confirm the the event listers are working in general as calling connection.close()
manually outputs !!closed
.
I asked the hapi.js community on GitHub if a passed object will be passed to plugins as a copy, but that's actually not the case.
Here's the code throwing the error:
console.log(server.root.app.connection) // {…} === connection
console.log(server.root.app.connection.open) // true
r.table('records').group('siteLocation').count().run(server.root.app.connection, (err, cursor) => {
...
})
To sum it up:
- Connection should be open as it never gets closed
- (Inside the plugin:) Can't get data from the database as RethinkDB says that the
First argument to 'run' must be an open connection.
Is there any way to find out why the connection is not open anymore?
RethinkDB version: 2.1.5
hapi.js version: 11.1.2
Thanks!