Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a setter method to sets Connection read timeout #1228

Open
kobikis opened this issue Jun 4, 2019 · 0 comments
Open

Create a setter method to sets Connection read timeout #1228

kobikis opened this issue Jun 4, 2019 · 0 comments

Comments

@kobikis
Copy link

kobikis commented Jun 4, 2019

In the following example the Connection timeout is 7sec and the url latency is 5sec but i'm getting java.net.SocketTimeoutException: Read timed out

`
@RunWith(SpringRunner.class)
public class FetcherConcurrentClientApplicationTests {

@test
public void simpleTest() {
Document doc = null;
long startTime = System.nanoTime();
try {
doc = Jsoup.connect("http://httpstat.us/200?sleep=5000").timeout(7000).get();
} catch (IOException e) {
e.printStackTrace();
}
long processingTime = System.nanoTime() - startTime;
System.out.println("Processing time: " + TimeUnit.NANOSECONDS.toMillis(processingTime));
assertNotNull(doc);
}
}
`

It's because that when JSoup create a connection it configure the Connection readTimeout to half of the request timeout.

`
private static HttpURLConnection createConnection(Connection.Request req) throws IOException {
final HttpURLConnection conn = (HttpURLConnection) (
req.proxy() == null ?
req.url().openConnection() :
req.url().openConnection(req.proxy())
);

        conn.setRequestMethod(req.method().name());
        conn.setInstanceFollowRedirects(false); // don't rely on native redirection support
        conn.setConnectTimeout(req.timeout());
        conn.setReadTimeout(req.timeout() / 2);

`

kobikis pushed a commit to kobikis/jsoup that referenced this issue Jun 4, 2019
kobikis pushed a commit to kobikis/jsoup that referenced this issue Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant