orientjs icon indicating copy to clipboard operation
orientjs copied to clipboard

How to capture timely CONNECTION ERROR with remote orientdb?

Open ghost opened this issue 8 years ago • 12 comments

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.

  1. in my js code.

     odb.open().then(function(){
    
     	odb.transport.connection.socket.once('error', (error) => {
     		console.log('socket error %s', error.code);
     		reconnect();
     	});
     })
    

    ....

  2. 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!!

ghost avatar Apr 10 '17 05:04 ghost

Hi @zhiguan-hanks

are you orientjs within Electron ?

Did you try directly with nodejs socket?

wolf4ood avatar Apr 12 '17 10:04 wolf4ood

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

ghost avatar Apr 13 '17 00:04 ghost

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

wolf4ood avatar Apr 13 '17 13:04 wolf4ood

Can you try on Windows 7? If you are the author.

ghost avatar Apr 13 '17 13:04 ghost

I tried over 100 times. This error catching means too much for us.

ghost avatar Apr 13 '17 13:04 ghost

Is this issue still relevant or does the workaround worked?

lvca avatar Apr 14 '17 12:04 lvca

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

ghost avatar Apr 14 '17 12:04 ghost

@zhiguan-hanks

can you try without electron if it has the same behaviour ?

wolf4ood avatar Apr 14 '17 13:04 wolf4ood

Ok. I will try after finishing my task in hands.

ghost avatar Apr 14 '17 13:04 ghost

Ok @zhiguan-hanks

let me know, otherwise i will set up a Windows environment and test it Thanks

wolf4ood avatar Apr 14 '17 13:04 wolf4ood

Sure! Thanks in advance.

ghost avatar Apr 14 '17 14:04 ghost

Hi maggiolo00 , here I report my try without Electron

  1. 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);
     });
    

`

  1. 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

  1. case B---disable the wifi about 1 second later, 'CONNECTION ERROR' caught. windows console:

socket error ECONNRESET

ghost avatar Apr 15 '17 03:04 ghost