Fraunhofer-IIS / libjapi

libjapi is a universal JSON to C API library. It receives newline-delimited JSON (NDJSON) messages via TCP and calls registered C functions. A JSON response is returned for each request. Furthermore, it is also possible to create push services, which asynchronously push JSON messages to the clients subscribed to them.
MIT License
3 stars 1 forks source link

server has to remove ungracefull disconnected zombie clients #49

Open fraunhofer-iis-bot opened 1 year ago

fraunhofer-iis-bot commented 1 year ago

In GitLab by @Michael-M-Baron on May 5, 2023, 16:06

We are currently facing a problem using the libjapi in Interstellar dbcd. In short, our libjapi-server is fixed to allow only one client at a time. If a client was connected and has network issues, the connection is lost but the client is still open inside the server. This means that no new client can connect to the server anymore and the aplication has to be restarted.

Under normal circumstances, the client will send an EOF while disconnecting. The server recognizes this, closes the socket and removes the client properly. Problems start to occur, when the client disconnects without terminating the connection properly (Due to network problems etc.). The client socket will then still be seen as active inside the server. The server needs to remove the client socket in such cases.

To fix this problem, a mechanism has to be implemented to remove ungracefull disconnected zombie clients inside the server. The server has to somehow verify if the client sockets are still connected properly. There are two ideas how to implement this:

  1. The server could frequently try to write dummy packages to the connected client sockets. If the write to the client doesnt work, the server could remove the client. It has to be ensured, that the client can handle these dummy package.
  2. A timeout mechanism could be implemented inside the server. If a client doesnt write after certain time interval, the server automatically closes the socket. For this approach, the client has to frequently ping the server to not get disconnected.

Both approaches should be optional and backwards compatible.

This seems to be also a kind of general problem working with servers/clients and TCP/IP. May be there are better solutions?

fraunhofer-iis-bot commented 1 year ago

In GitLab by @vornkat-iis on May 8, 2023, 12:02

created branch 49-server-has-to-remove-ungracefull-disconnected-zombie-clients to address this issue

fraunhofer-iis-bot commented 1 year ago

In GitLab by @schreimz on May 10, 2023, 18:01

This issue is found here: https://git01.iis.fhg.de/abt-hfs/interstellar/dbcd/-/issues/371 Implementing tcp keepalive does not solve the problem for interstellar, since an additional websocketd is running between japi server and client.

Keepalive is in any way an usefull feature if configurable (through japi function)

fraunhofer-iis-bot commented 1 year ago

In GitLab by @schreimz on May 10, 2023, 18:01

mentioned in issue abt-hfs/interstellar/dbcd#371