Non-Java Java Socket Timeout

I have a non-blocking Java server that monitors all socket channels in a selector. Then I establish 500 connections to the server and regularly send data. Each piece of data received by the server is returned back to the client.

The problem occurs when the test works wonderfully for several hours, and then suddenly all the sockets that the server manages to throw an IOException timeout when trying to read data.

I examined if the client thread was hungry (and not send data), but I yield to the client thread that iterates through all the sockets and writes the data. Traffic seems to be constantly flowing properly, but after a while it just dies. What ideas can trigger this behavior?

I work on the Linux platform with the latest iteration of Java 6. My application runs two threads: one for the server and one for all clients. Thanks in advance!

Extras: The problem is with Linux, not with my code. When I run the same setup in a Windows window (on the same hardware), it never expires, but after a few hours they start to occur on Linux. On Linux, there must be some kind of TCP parameter that calls it. Thanks for the suggestion.

+4
source share
3 answers

The problem is with Linux, not with my code. When I run the same setup in a Windows window (on the same hardware), it never expires, but after a few hours they start to occur on Linux. On Linux, there must be some kind of TCP parameter that calls it. Thanks for the suggestion.

+1
source

The -doCloseWithReadPending option in Java and JRE version 1.5 or 5.0 allows one thread to close the socket when it is expected to read on the same socket from another thread.

When the close () function is called on a socket that has an outstanding read call from another thread, close () by default blocks the socket until the read call completes.

With the -doCloseWithReadPending parameter, a close close call closes the socket and a SocketException is thrown with a "Socket closed" message in the context of a thread with a pending read.

I don’t know if this is the main cause of your problem without seeing the code, but I thought I would add it here if it affects your problem.

0
source

So, as in the case when it works (Windows with a recent JVM), and in the case when it is not (Linux with a recent JVM), the server and the client are on the same machine in the same JVM?

Can you explain what it means "everything is suddenly gradual"? For example, after a few hours β€” and always the same number of hours β€” then within a few seconds will all server sockets throw exceptions?

You do not mention a client thread reading the data that is returned. Perhaps it stopped, and you did not notice. (What is a client thread when a server thread encounters 500 quick exceptions? Try a few stack dumps in a row to see them.)

0
source

Source: https://habr.com/ru/post/1286531/


All Articles