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

  • SEARCH
  • Home
  • 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 298585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:44:42+00:00 2026-05-12T06:44:42+00:00

I have the following situation: using a classical Java server (using ServerSocket) I would

  • 0

I have the following situation: using a “classical” Java server (using ServerSocket) I would like to detect (as rapidly as possible) when the connection with the client failed unexpectedly (ie. non-gracefully / without a FIN packet).

The way I’m simulating this is as follows:

  • I’m running the server on a Linux box
  • I connect with telnet to the box
  • After the connection has succeeded I add “DROP” rule in the box’s firewall

What happens is that the sending blocks after ~10k of data. I don’t know for how long, but I’ve waited more than 10 minutes on several occasions. What I’ve researched so far:

  • Socket.setSoTimeout – however this affects only reads. If there are only writes, it doesn’t have an effect
  • Checking for errors with PrintWriter.checkError(), since PW swallows the exceptions – however it never returns true

How could I detect this error condition, or at least configure the timeout value? (either at the JVM or at the OS level)

Update: after ~20min checkError returned true on the PrintWriter (using the server JVM 1.5 on a CentOS machine). Where is this timeout value configured?

  • 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-05-12T06:44:42+00:00Added an answer on May 12, 2026 at 6:44 am

    The ~20 min timeout is because of standard TCP settings in Linux. It’s really not a good idea to mess with them unless you know what you’re doing. I had a similar project at work, where we were testing connection loss by disconnecting the network cable and things would just hang for a long time, exactly like you’re seeing. We tried messing with the following TCP settings, which made the timeout quicker, but it caused side effects in other applications where connections would be broken when they shouldn’t, due to small network delays when things got busy.

    net.ipv4.tcp_retries2
    net.ipv4.tcp_syn_retries
    

    If you check the man page for tcp (man tcp) you can read about what these settings mean and maybe find other settings that might apply. You can either set them directly under /proc/sys/net/ipv4 or use sysctl.conf. These two were the ones we found made the send/recv fail quicker. Try setting them both to 1 and you’ll see the send call fail a lot faster. Make sure to take not of the current settings before changing them.

    I will reiterate that you really shouldn’t mess with these settings. They can have side effects on the OS and other applications. The best solution is like Kitson says, use a heartbeat and/or application level timeout.

    Also look into how to create a non-blocking socket, so that the send call won’t block like that. Although keep in mind that sending with a non-blocking socket is usually successful as long as there’s room in the send buffer. That’s why it takes around 10k of data before it blocks, even though you broke the connection before that.

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

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 141k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the random module: http://docs.python.org/library/random.html import random random.sample(set([1, 2, 3,… May 12, 2026 at 8:02 am
  • Editorial Team
    Editorial Team added an answer You can not handle this directly: As you can see… May 12, 2026 at 8:02 am
  • Editorial Team
    Editorial Team added an answer You may be able to wrap the whole function as… May 12, 2026 at 8:02 am

Related Questions

I know there is a lot of similar questions are tons of great answers
I have the following situation: A user will define a certain filter on a
I currently use Python for most of my programming projects (mainly rapid development of
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
I am really confused how to compute precision and recall in clustering applications. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.