SEGFAULT after `cluster.close()`
Description
Environment
Gerrit Reviews
Release Notes Description
Activity
J.David Luque February 3, 2020 at 10:53 PM
@Brett Lawson
Its true, I are commented the call to _connect in my snippet, i wanted to show what happens when i was triying to 'reconnect' to the cluster.
— The SDK is not designed to enable reconnection of an existing Cluster but instead should create a new Cluster after invoking `close()` (unfortunately, Node.js doesn't have a good way to enforce this).
I think this is a bad decision, mostly when a SEGFAULT is exposed to the user. Some checks should be implemented.
I am currently using couchnode in a serverless AWS Lambda, thats requires to close all async tasks under the event loop before finishing each request, and reopen them all when a new requests arrives. Should i re-instance all couchnode classes associated to a cluster connection, because they are all in a obscured 'invalid' state?
Thanks
Brett Lawson February 3, 2020 at 4:20 PM
Hey @J.David Luque,
The use of `cluster._connect()` is intended to be internal use only and should never be used by a developer. The SDK is not designed to enable reconnection of an existing Cluster but instead should create a new Cluster after invoking `close()` (unfortunately, Node.js doesn't have a good way to enforce this).
Cheers, Brett
Matt Ingenthron February 2, 2020 at 12:16 AM
Thanks for reporting that @J.David Luque, we'll have a look soon.
Scope, Collection and Bucket classes holds a reference to Connection. When all the connections are closed on the cluster, these classes mantains the reference to a destroyed connection, causing a SEGFAULT.
```javascript
const cluster = new cb.Cluster('...');
const bucket = cluster.bucket('default');
const collection = bucket.defaultCollection()
const r1 = await collection.get('...')
console.log('response 1', r1)
await cluster.close(); // close all connections
//await cluster._connect() // <--- SEGFAULT here
const r2 = await collection.get('...') // <--- SEGFAULT here
console.log('response 2', r2)
```