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 9205415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:56:42+00:00 2026-06-17T23:56:42+00:00

First, some background. There is a worker which expands/resolves bunch of short URLS: http://t.co/example

  • 0

First, some background. There is a worker which expands/resolves bunch of short URLS:

http://t.co/example -> http://example.com

So, we just follow redirects. That’s it. We don’t read any data from the connection. Right after we got 200 we return the final URL and close InputStream.

Now, the problem itself. On a production server one of the resolver threads hangs inside the InputStream.close() call:

"ProcessShortUrlTask" prio=10 tid=0x00007f8810119000 nid=0x402b runnable [0x00007f882b044000]
   java.lang.Thread.State: RUNNABLE
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at java.io.BufferedInputStream.skip(BufferedInputStream.java:352)
        - locked <0x0000000561293aa0> (a java.io.BufferedInputStream)
        at sun.net.www.MeteredStream.skip(MeteredStream.java:134)
        - locked <0x0000000561293a70> (a sun.net.www.http.KeepAliveStream)
        at sun.net.www.http.KeepAliveStream.close(KeepAliveStream.java:76)
        at java.io.FilterInputStream.close(FilterInputStream.java:155)
        at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(HttpURLConnection.java:2735)
        at ru.twitter.times.http.URLProcessor.resolve(URLProcessor.java:131)
        at ru.twitter.times.http.URLProcessor.resolve(URLProcessor.java:55)
        at ...

After a brief research, I understood that skip() is called to clean up the stream before sending it back to the connections pool (if keep-alive is set on?). Still I don’t understand how to avoid this situation. Moreover, I doubt if there is some bad design in our code or there is problem in JDK.

So, the questions are:

  1. Is it possible to avoid hanging on close()? Guarantee some reasonable
    timeout, for example.
  2. Is it possible to avoid reading data from connection at all?
    Remember I just want the final URL. Actually, I think, I don’t want
    skip() to be called at all …

Update:

KeepAliveStream, line 79, close() method:

    // Skip past the data that's left in the Inputstream because
    // some sort of error may have occurred.
    // Do this ONLY if the skip won't block. The stream may have
    // been closed at the beginning of a big file and we don't want
    // to hang around for nothing. So if we can't skip without blocking
    // we just close the socket and, therefore, terminate the keepAlive
    // NOTE: Don't close super class
    try {
        if (expected > count) {
        long nskip = (long) (expected - count);
        if (nskip <= available()) {
            long n = 0;
            while (n < nskip) {
            nskip = nskip - n;
            n = skip(nskip);} ...

More and more it seems to me that there is a bug in JDK itself. Unfortunately, it’s very hard to reproduce this …

  • 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-17T23:56:43+00:00Added an answer on June 17, 2026 at 11:56 pm

    The implementation of KeepAliveStream that you have linked, violates the contract under which available() and skip() are guaranteed to be non-blocking and thus may indeed block.

    The contract of available() guarantees a single non-blocking skip():

    Returns an estimate of the number of bytes that can be read (or
    skipped over) from this input stream without blocking by the next
    caller of a method for this input stream. The next caller might be
    the same thread or another thread. A single read or skip of this
    many bytes will not block, but may read or skip fewer bytes.

    Wheres the implementation calls skip() multiple times per single call to available():

        if (nskip <= available()) {
            long n = 0;
            // The loop below can iterate several times,
            // only the first call is guaranteed to be non-blocking. 
            while (n < nskip) { 
            nskip = nskip - n;
            n = skip(nskip);
            }
    

    This doesn’t prove that your application blocks because KeepAliveStream incorrectly uses InputStream. Some implementations of InputStream may possibly provide stronger non-blocking guarantees, but I think it is a very likely suspect.

    EDIT: After a bit more research, this is a very recently fixed bug in JDK: https://bugs.openjdk.java.net/browse/JDK-8004863?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel. The bug report says about an infinite loop, but a blocking skip() could also be a result. The fix seems to address both issues (there is only a single skip() per available())

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

Sidebar

Related Questions

First some background, I've written an open source .NET library, named Duplicitiy (on github.com),
Some setup background first: I have a cronjob which runs a PHP file called
First some background: I'm working on an application and I'm trying to follow MVVM
Hi and thanks for your attention. First some background on the question: I have
First, some background: I'm developing a web application using Python. All of my (text)
this is my first question on stack overflow. Some quick background, this is not
First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web
First some background. I'm parsing a simple file format, and wish to re-use the
First some background: The company I work for have decided to create an iPhone
First some brief background: I have an existing ASP.NET MVC 1 application using Entity

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.