basex-node does not handle server disconnection gracefully #9

Closed
opened 2013-02-18 06:08:12 +00:00 by hanshuebner · 5 comments
hanshuebner commented 2013-02-18 06:08:12 +00:00 (Migrated from github.com)

Hi,

when leaving my node process connected to BaseX running over night, it crashed when it lost connection to the database server. It seems that there is currently no way to prevent this, as node-basex does not handle the possible closing of the socket by the database server, and tries to interact with a closed socket, which results in an uncaught exception.

It would be useful if an event would be generated when a Session lost its connection (by making it an EventEmitter and forwarding the 'end' event). Furthermore, session.close() should detect when the socket is already closed and not try to read or write from it in that case.

This would allow application code to set up an event handler that logged the event and performed an automatic reconnection, if desired.

I can come up with a patch if you don't have the time to look into implementing this yourself. Please let me know.

Thanks!
Hans

Hi, when leaving my node process connected to BaseX running over night, it crashed when it lost connection to the database server. It seems that there is currently no way to prevent this, as node-basex does not handle the possible closing of the socket by the database server, and tries to interact with a closed socket, which results in an uncaught exception. It would be useful if an event would be generated when a Session lost its connection (by making it an EventEmitter and forwarding the 'end' event). Furthermore, session.close() should detect when the socket is already closed and not try to read or write from it in that case. This would allow application code to set up an event handler that logged the event and performed an automatic reconnection, if desired. I can come up with a patch if you don't have the time to look into implementing this yourself. Please let me know. Thanks! Hans
apb2006 commented 2013-02-18 10:24:19 +00:00 (Migrated from github.com)

Hi Hans,

Handling disconnection and reconnect has been on the TODO list for a while :-). Your event proposal seems fine to me. If it is something you are looking for quickly I am very happy to take patches or pull requests.

Hi Hans, Handling disconnection and reconnect has been on the TODO list for a while :-). Your event proposal seems fine to me. If it is something you are looking for quickly I am very happy to take patches or pull requests.
jesseclark commented 2014-04-04 23:35:44 +01:00 (Migrated from github.com)

I noticed today that after leaving my application running with no requests for a few days and then trying to process an action, it just hung. I need to debug further but I suspect that the BaseX session got disconnected and my app tried to use the invalid session.

I can work around by creating a new session per request but that seems less than ideal.

I'm willing to help implement disconnect handling if you would like to discuss the best solution.

I noticed today that after leaving my application running with no requests for a few days and then trying to process an action, it just hung. I need to debug further but I suspect that the BaseX session got disconnected and my app tried to use the invalid session. I can work around by creating a new session per request but that seems less than ideal. I'm willing to help implement disconnect handling if you would like to discuss the best solution.
apb2006 commented 2014-04-05 00:00:44 +01:00 (Migrated from github.com)

Very happy to have your help on this. I dont really have a solution in mind, two approaches are:

  1. simple-basex has this emit mechanism which seems like a good starting point
    https://github.com/hanshuebner/simple-basex/blob/master/index.js#L64
    @hanshuebner Do you have any thoughts on this?

  2. node_redis, which was an inspiration when starting basex-node, has much more
    https://github.com/mranney/node_redis/blob/master/index.js#L442

Very happy to have your help on this. I dont really have a solution in mind, two approaches are: 1) simple-basex has this emit mechanism which seems like a good starting point https://github.com/hanshuebner/simple-basex/blob/master/index.js#L64 @hanshuebner Do you have any thoughts on this? 2) node_redis, which was an inspiration when starting basex-node, has much more https://github.com/mranney/node_redis/blob/master/index.js#L442
hanshuebner commented 2014-04-05 08:08:54 +01:00 (Migrated from github.com)

2014-04-04 19:00 GMT-04:00 Andy Bunce notifications@github.com:

  1. simple-basex has this emit mechanism which seems like a good starting
    point

https://github.com/hanshuebner/simple-basex/blob/master/index.js#L64

@hanshuebner https://github.com/hanshuebner Do you have any thoughts on
this?

I have not looked into this in a long time, but from looking at the code,
it appears that simple-basex just forwards the connection error to
application as connectionError event and leaves it up to the application to
handle the reconnection. I think this is the right strategy, as the
application may want to recover from the connection failure and
resynchronize to the database state as it will not be always clear what has
been written by the database before the connection error occurs.

I cannot comment on how hard or easy it would be to use the same strategy
of forwarding events to the application work in basex-node.

2014-04-04 19:00 GMT-04:00 Andy Bunce notifications@github.com: > 1) simple-basex has this emit mechanism which seems like a good starting > point > > https://github.com/hanshuebner/simple-basex/blob/master/index.js#L64 > > @hanshuebner https://github.com/hanshuebner Do you have any thoughts on > this? > > I have not looked into this in a long time, but from looking at the code, > it appears that simple-basex just forwards the connection error to > application as connectionError event and leaves it up to the application to > handle the reconnection. I think this is the right strategy, as the > application may want to recover from the connection failure and > resynchronize to the database state as it will not be always clear what has > been written by the database before the connection error occurs. I cannot comment on how hard or easy it would be to use the same strategy of forwarding events to the application work in basex-node.
apb2006 commented 2021-09-29 22:01:17 +01:00 (Migrated from github.com)

See examples/issue11.js for one approach

See `examples/issue11.js` for one approach
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#9
No description provided.