Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Missing Socket Timeout #42

Closed
GoogleCodeExporter opened this issue Mar 17, 2015 · 3 comments
Closed

Missing Socket Timeout #42

GoogleCodeExporter opened this issue Mar 17, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Try to send a message but block the network.

What is the expected output? What do you see instead?

I expect, after some time a TimeoutExceptio, instead the process wait 
forever... 


What version of the product are you using? On what operating system?
The last one.

Please provide any additional information below.
In Sender.java there is 

    HttpURLConnection conn = getConnection(url);
    conn.setDoOutput(true);
    conn.setUseCaches(false);
    conn.setFixedLengthStreamingMode(bytes.length);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", contentType);
    conn.setRequestProperty("Authorization", "key=" + key);
    OutputStream out = conn.getOutputStream();


And get connection is defined as:
 /**
   * Gets an {@link HttpURLConnection} given an URL.
   */
  protected HttpURLConnection getConnection(String url) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    return conn;
  }



I think somewhere we need to put setConnectTimeout and setReadTimeout.


Original issue reported on code.google.com by l.visco...@opengate.biz on 17 Mar 2014 at 4:05

@GoogleCodeExporter
Copy link
Author

I've made a little test:
blocking the network connection to android.googleapis.com using iptables with 
the following command:
sudo iptables -I OUTPUT -d 173.194.70.95 -j DROP

The code blocks in conn.getOutputStream().

In the attachment my suggestion for fixing the problem: adding a constant for 
network timeout and adding setConnectTimeout and setReadTimeout in 
getConnection method.





Original comment by l.visco...@opengate.biz on 18 Mar 2014 at 9:04

Attachments:

@dmg3
Copy link

dmg3 commented Dec 16, 2015

I was unable to replicate with the iptables trick; however, on my production server, I believe I encountered this issue during a period of intermittent network connectivity. I have 3 jobs that are permanently "hung", and I know that they were attempting to send different messages at the time of my network outage. Other jobs that were running at the time were spewing exceptions which were originating in the Sender.post method (where the conn.getOutputStream() is called ) . Exceptions such as ConnectionReset, Remote Host closed connection during handshake, connection timed out, etc. So I believe that some combination of network trouble will cause this method to block or hang indefinitely. +1 for the suggested fix of set timeout values

@kroikie
Copy link
Contributor

kroikie commented Feb 24, 2016

This PR allows for the setting of connection timeout values. If this issue persists please submit an issue with more detail if possible.

@kroikie kroikie closed this as completed Feb 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants