orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

tons of logs "Socket closed" for each REST-API client program that terminates

Open langhha opened this issue 10 years ago • 21 comments

OrientDB Version, operating system, or hardware.

  • v2.2.5

Operating System

  • [x] Linux

Expected behavior and actual behavior

We spawn a many client programs about every some seconds, loading files with data-records into the ODB server, via the REST-API. It seems that each time a client program terminates, the server adds a log entry as follows:

... 2016-08-23 15:17:04:675 SEVER Internal server error: java.net.SocketException: Socket closed [ONetworkProtocolHttpDb] 2016-08-23 15:17:05:907 SEVER Internal server error: java.net.SocketException: Socket closed [ONetworkProtocolHttpDb] 2016-08-23 15:17:07:119 SEVER Internal server error: java.net.SocketException: Socket closed [ONetworkProtocolHttpDb] ...

My questions:

  • a REST-API is using HTTP connections, each of which is supposed to be state-less ; I think it is setting up a socket, then sends the data over that socket, and would close this socket when the program terminates. As expected. So why is the server complaining with such logs ?
  • the documentation of ODB might contain some more information about the different log messages that can be spawned by the server, so that we can understand the situations that might led to those logs

langhha avatar Aug 23 '16 13:08 langhha

What do you use to make HTTP calls? What's your HTTP settings (keep-alive, etc)

lvca avatar Aug 24 '16 15:08 lvca

@lvca Luca, it's a simple POST without any keep-alive settings, sending a JSON packed series of records from an input file to ODB; at the end, the (client-)program simply exits.

langhha avatar Aug 25 '16 22:08 langhha

If you do the same with CURL, do you same the same error?

lvca avatar Aug 27 '16 23:08 lvca

Cannot test with CURL, because I am using Perl modules (REST::Client) which implement low level HTTP sockets

Meanwhile upgraded to version 2.2.7

I notice now that our server was hanging, could not accept any more network connections because maximum (1000) was reached. There were indeed 1000 or so open sockets on port 2480 in CLOSE_WAIT status.

I must admit that we spawn very fast individual client connections to the server, that live very short. Apparently the server is waiting too long before cleaning up the closed sockets.

  • server config should be tuned to be able to deal with so many, short living client connections (raise number of connections allowed, and/or reduce dramatically its time period that it waits for closed connections)
  • or we must hope that the client programs behave differently and are not spawning so many short living connections; clearly we (=server admins) don't have very tight control over this

The tuning of server config is best, I guess, because there we are sure that we can control the behaviour. -> where can we reduce the time that the server waits before it cleans up closed sockets ?

langhha avatar Aug 29 '16 09:08 langhha

RF793 says CLOSE_WAIT is the TCP/IP stack waiting for the local application to release the socket. So, it hangs because it has received the information that the remote host has initiated a disconnection and is closing its socket, upon what the local application did not close its own side. No it is not relevant to search for any tuning at the O/S level, it's ODB's responsibility to close such sockets promptly.

langhha avatar Aug 29 '16 10:08 langhha

@rdelangh why can't you use CURL for a test? So we can exclude your application as responsible. How do you close the socket once done?

lvca avatar Aug 29 '16 14:08 lvca

Our programs are historically written in Perl, so to reduce porting needs to a minimum we are now connecting from these same Perl programs to the OrientDB via a CPAN module "REST::Client", which in turn makes use of LWP module for the HTTP(s) connections.

Each bulk transaction with INSERTs (packed in a JSON structure) that I want to send to OrientDB, is sent with a new HTTP connection (I guess), just like CURL would do.

To help me understand why/how this REST::Client module of Perl would (or not) misbehave, can you please elaborate more about the conditions in which OrientDB REST API would spawn such log messages

2016-09-06 11:14:49:956 SEVER Internal server error: java.net.SocketException: Socket closed [ONetworkProtocolHttpDb]

langhha avatar Sep 06 '16 09:09 langhha

If you use CURL from the command linen or even studio, you can see the server never dump that message. So it has to be related with the way you manage the connection, specially when the client close it.

lvca avatar Sep 06 '16 15:09 lvca

@rdelangh any news about this?

lvca avatar Sep 23 '16 18:09 lvca

@lvca My Perl programs use the CPAN module "REST::Client" for the communications with ODB. I am trying to figure out where in this module the HTTP transport is done in such a way that we get these logs from the ODB server. It would help me a lot if you can describe from the ODB code, in which kind of conditions it will spawn these "Socket closed" logs.

langhha avatar Sep 26 '16 08:09 langhha

@tglman can you please share some details about what exactly you might have changed in the code that relates to these "Socket closed" messages ?

langhha avatar Nov 15 '16 10:11 langhha

@tglman , @lvca currently running with build 2.2.x@ra3e56d7c76285480f40161c9dd2d1ea29473953f; 2016- 11-15 08:47:42+0000, but we still get these log messages:

...
2016-11-15 11:14:36:594 SEVER Internal server error:
java.net.SocketException: Socket closed [ONetworkProtocolHttpDb]
...

langhha avatar Nov 15 '16 10:11 langhha

hi @rdelangh,

we had done some refactor in the past for support streaming that was creating a few issue, so we almost reverted it, now is enabled only if there is an "TE" header.

The error Socked Closed is throw by java when you try to read or write data to/from a socked that is closed, i guess this can happen if the "Keep-Alive" header is set to true but the connection is closed, anyway i'm going to add some debug logs for determine more clearly the place this error happen.

Regards

tglman avatar Nov 16 '16 15:11 tglman

hi @rdelangh,

I fixed a wrong flag on the streaming and add a debug line, in case is needed we can track the stack trace of eventual errors, due to the fact that you where already trying the snapshot, can you try the last snapshot ?

Bye

tglman avatar Nov 17 '16 13:11 tglman

@tglman thx for that; I am running now with orientdb-community-2.2.14-20161116.124700-1 ; can you please confirm in which snapshot your modifications have been/will be included ?

langhha avatar Nov 17 '16 15:11 langhha

the commit was done today, so better a snapshot > 17 over the midday, like 2.2.14-20161117.160515

tglman avatar Nov 17 '16 17:11 tglman

@tglman I have just installed and started version 2.2.14-SNAPSHOT-20161118.121331-4, but the logs still spawn at each connection-termination these lines:

2016-11-18 21:03:30:645 SEVER Internal server error:
java.net.SocketException: Socket closed [ONetworkProtocolHttpDb]

So apparently there is still something else not dealing right with the end of HTTP (REST) connections...

langhha avatar Nov 18 '16 20:11 langhha

hi @rdelangh,

I fixed some double response bug in the http that could cause this kind of problem, this should be released in 2.2.17, anyway i see that often you test the snapshots, so feel free to test the 2.2.17-SNAPSHOT.

Bye

tglman avatar Feb 08 '17 17:02 tglman

hi @rdelangh,

This should be fixed and released, closing

tglman avatar Mar 27 '17 13:03 tglman

hi @tglman in which release should this be fixed? Using 2.2.18-20170304.005202-22, we still have this server output message after each and every REST connection (hence zillions of such messages!):

...
2017-03-23 20:07:59:419 SEVER Internal server error:
java.net.SocketException: Socket closed [ONetworkProtocolHttpDb]
...

langhha avatar Mar 27 '17 13:03 langhha