Socket errors handling #22

Closed
opened 2017-03-23 05:54:36 +00:00 by jacobborisov · 4 comments
jacobborisov commented 2017-03-23 05:54:36 +00:00 (Migrated from github.com)

Hello. When I open BaseX session and then restart the server while the session keeps idle, I've got such error if I try to perform a query:

SOCKET ERROR:  { Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:291:12)
    at Session.write (/usr/lib/node_modules/basex/index.js:216:25)
    at Session.sendQueueItem (/usr/lib/node_modules/basex/index.js:395:14)
    at Session.send_command (/usr/lib/node_modules/basex/index.js:369:14)
    at new Query (/usr/lib/node_modules/basex/lib/query.js:243:10)
    at Session.query (/usr/lib/node_modules/basex/index.js:280:16)
    at rpn.then (/root/testscript.js:78:20)
    at propagateAslWrapper (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:421:23)
    at /usr/lib/node_modules/pm2/node_modules/async-listener/index.js:458:70
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:129:7) code: 'EPIPE' }

Is it possible to catch such errors in the user code? If not, I guess it's need to implement some error handling features for Session and/or Query constructors.

As I can see at this time there is only console output performed:

function socketError(e) {
    if (e.code == 'ECONNREFUSED') {
        console.log('ECONNREFUSED: connection refused. Check BaseX server is running.');
    } else {
        console.log("SOCKET ERROR: ", e);
    }
}
Hello. When I open BaseX session and then restart the server while the session keeps idle, I've got such error if I try to perform a query: ``` SOCKET ERROR: { Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:291:12) at Session.write (/usr/lib/node_modules/basex/index.js:216:25) at Session.sendQueueItem (/usr/lib/node_modules/basex/index.js:395:14) at Session.send_command (/usr/lib/node_modules/basex/index.js:369:14) at new Query (/usr/lib/node_modules/basex/lib/query.js:243:10) at Session.query (/usr/lib/node_modules/basex/index.js:280:16) at rpn.then (/root/testscript.js:78:20) at propagateAslWrapper (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:421:23) at /usr/lib/node_modules/pm2/node_modules/async-listener/index.js:458:70 at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:129:7) code: 'EPIPE' } ``` Is it possible to catch such errors in the user code? If not, I guess it's need to implement some error handling features for Session and/or Query constructors. As I can see at this time [there is](https://github.com/apb2006/basex-node/blob/master/index.js#L421) only console output performed: ``` function socketError(e) { if (e.code == 'ECONNREFUSED') { console.log('ECONNREFUSED: connection refused. Check BaseX server is running.'); } else { console.log("SOCKET ERROR: ", e); } } ```
apb2006 commented 2017-03-23 10:05:47 +00:00 (Migrated from github.com)

This is a long standing deficiency see #9
I have created a dev branch where the session object emits socketError events
https://github.com/apb2006/basex-node/blob/dev/index.js#L156

An example
https://github.com/apb2006/basex-node/blob/dev/examples/issue22.js

Would this meet your requirements?

This is a long standing deficiency see #9 I have created a dev branch where the session object emits socketError events https://github.com/apb2006/basex-node/blob/dev/index.js#L156 An example https://github.com/apb2006/basex-node/blob/dev/examples/issue22.js Would this meet your requirements?
jacobborisov commented 2017-03-23 15:33:03 +00:00 (Migrated from github.com)

I think it's better than nothing at least and I will be able to deal with these errors. So if it doesn't conflict with your API design opinions you should push this patch to the stable branch I guess. Thanks.

I think it's better than nothing at least and I will be able to deal with these errors. So if it doesn't conflict with your API design opinions you should push this patch to the stable branch I guess. Thanks.
apb2006 commented 2017-03-23 22:09:50 +00:00 (Migrated from github.com)

v0.9.0 now on npm has this update and a few cleanups.

I have also updated
https://github.com/apb2006/basex-node/blob/dev/examples/issue22.js
to show use of this feature.
I am very happy to take suggestions/pull request for any improvements. I am not an expert on the range of socket errors that could arise here.

v0.9.0 now on npm has this update and a few cleanups. I have also updated https://github.com/apb2006/basex-node/blob/dev/examples/issue22.js to show use of this feature. I am very happy to take suggestions/pull request for any improvements. I am not an expert on the range of socket errors that could arise here.
apb2006 commented 2017-04-05 12:27:20 +01:00 (Migrated from github.com)

Closing this as the v0.9 release provides the means to detect and respond to socket errors. See #9 for additional features that could be implement to provide cleaner session handling in these cases.

Closing this as the v0.9 release provides the means to detect and respond to socket errors. See #9 for additional features that could be implement to provide cleaner session handling in these cases.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
quodatum/basex-node#22
No description provided.