Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:38:59+00:00 2026-06-07T19:38:59+00:00

i am running into a similar issue as described here: Java Linux Nonblocking Socket

  • 0

i am running into a similar issue as described here: Java Linux Nonblocking Socket Timeout Behavior

I have an application implemented with Java NIO. It keeps track of a bunch of sockets, and when they’re ready for reading, my application will read in a loop (removed code and some logic for brevity):

        if (selkey.isReadable()) {
            int nread;
            while (true) {
                // read the header
                nread = mSocketChannel.read(mHeaderBuffer);
                if (nread == -1)
                    return;
                handle_message_header();
                // read the body
                nread = mSocketChannel.read(mPayloadBuffer);
                if (nread == -1)
                    return;
                handle_message_body();
            }
        }

But very, very rarely I receive a timeout exception in the first read():

    java.io.IOException: Connection timed out
    at sun.nio.ch.FileDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:202)
    at sun.nio.ch.IOUtil.read(IOUtil.java:175)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:243)

I digged into the jdk sources, and the read0 function simply calls read() on the socket handle. The “Connection timed out” exception is thrown if read() returns -1 and errno == ETIMEDOUT.

We do not use soSetTimeout() or the tcp keepalive option. And since i was seeing this only on a client’s cluster i am not able to reproduce it (nor do i have the output of netstat or other tools).

I wonder in which cases does the linux kernel return ETIMEDOUT in a nonblocking read()? Is this a bug or a feature?

More information about the machine on which this appeared:

Linux slave1 2.6.18-164.e15 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
CentOS 5.4

Thanks
Chris

Edit:
According to my log file (and the program flow), the socket was created when the server accepted an incoming connection. Then there was at least one successful recv from that socket, but twice the server then failed to write. And then i caught the exception when reading.
The log file does not have much information – i am therefore not 100% sure about my analysis so far. I have added lots of debug output to the socket routines and now i am better prepared for the next time.

Thanks for all the helpful comments!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:39:01+00:00Added an answer on June 7, 2026 at 7:39 pm

    You are reading from a connection that you haven’t completed properly. Probably you did the connect in non-blocking mode and you either haven’t received the OP_CONNECT event; you haven’t called finishConnect(); or it didn’t return true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running into an issue similar to the one described here: NSFetchedResultsControllerDelegate not
I am running into the following issue while profiling an application under VC6. When
Running into a problem. I have a table defined to hold the values of
I'm running into a Spring (3.1) mapping conundrum: I have a simple, findAll method:
I'm running into a bit of an issue. My software needs to know when
So i am running into a major issue. I am currently trying to use
I'm running into an issue using a DataGridView bound to a iBindingListView implementation (third
I'm creating a pretty simple form, and I'm running into an issue with Controls/components
Found a similar post here but I am running a Mac so the first
I'm running into an issue with Opera not rendering my HTML5 site properly. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.