How to capture timely CONNECTION ERROR with remote orientdb?
Hi,
My case is maybe of a weird kind. Users access the Orientdb directly from chrome browsers by Orientjs, and keep the connection alive till signout. So once disconnection or connection errors occur, the events must be captured instantly and reconnection to be called.
I try the following.
-
in my js code.
odb.open().then(function(){ odb.transport.connection.socket.once('error', (error) => { console.log('socket error %s', error.code); reconnect(); }); })....
-
in your ../lib/transport/binary/connection.js --line 132
`
var socket = net.createConnection(this.port, this.host);
//Sunrise
socket.setTimeout(10);
socket.setKeepAlive(true);
// End Sunrise
socket.setNoDelay(true);
`
On my win 7 desktop, if the wifi connection disabled, 'connection error' can be caught almost simultaneously in less than 10ms; but if wifi disconnected, 'connection error' caught seconds later.
What are my mistakes? Would you kindly lead my way? Thanks a lot!!
Hi @zhiguan-hanks
are you orientjs within Electron ?
Did you try directly with nodejs socket?
Hi, nice to see your reply.
Yes my orientjs is within Electron! So the access to Orientdb completely depends on orientjs. I tried to go into orientjs lines just intending to workaround my issue mentioned here. I need your help! Thanks.
Sunrise zhang
hi @zhiguan-hanks
i was not able to reproduce it on OSX
did your workaround work?
//Sunrise
socket.setTimeout(10);
socket.setKeepAlive(true);
// End Sunrise
Can you try on Windows 7? If you are the author.
I tried over 100 times. This error catching means too much for us.
Is this issue still relevant or does the workaround worked?
I guess, I didn't express clear due to my poor English. Sorry.
I confirm the following code doesn't work. I guess it's not relevant. I haven't enough time to go further into your code.
//Sunrise socket.setTimeout(10); socket.setKeepAlive(true); // End Sunrise
@zhiguan-hanks
can you try without electron if it has the same behaviour ?
Ok. I will try after finishing my task in hands.
Ok @zhiguan-hanks
let me know, otherwise i will set up a Windows environment and test it Thanks
Sure! Thanks in advance.
Hi maggiolo00 , here I report my try without Electron
-
test.js `
var OrientDB = require('orientjs').ODatabase, config={ "host": "xxx.xxx.com", "port": 2424, "name": "testDb", username: 'admin', password: 'admin', "useToken": true }, db = new OrientDB(config); db.open().then( () => { console.log('%s opened....',config.name); db.transport.connection.socket.once('error', (error) => { console.log('socket error %s', error.code); }); db.transport.connection.socket.once('close', (error) => { console.log('socket close %s-$s', error.code,error.message); }); }) .catch( (error) => { console.log('fail to open: %s', error); });
`
- run D:\test>node test.js
testDb opened....
3.case A---disconnect the wifi about 60 seconds later, 'CONNECTION ERROR' caught. windows console:
socket error ECONNRESET
- case B---disable the wifi about 1 second later, 'CONNECTION ERROR' caught. windows console:
socket error ECONNRESET