nemccarthy / stash-pullrequest-builder-plugin

A Jenkins plugin for Building Stash Pull Requests
https://wiki.jenkins-ci.org/display/JENKINS/Stash+pullrequest+builder+plugin
Other
64 stars 130 forks source link

SocketTimeout causes rebuilding a PR multiple times #101

Closed MartinMReed closed 4 years ago

MartinMReed commented 8 years ago

I've run into an issue where pull requests keep getting built over and over regardless of whether the previous run was a success or failure. It is happening in the scenario where a SocketTimeoutException is thrown while retrieving the pull request comments. In our setup we have Jenkins and BitBucket on two different networks, so sometimes there are connection issues.

In StashApiClient.getPullRequestComments(String, String, String) there is a try/catch block. If a SocketTimeoutException is thrown while reading any of the comment responses, this method will consume the exception and return an empty list. The empty list then triggers the build to run again because the plugin thinks no previous attempts were made.

Pull Request #102 has been created to cascade the exception back to the top (StashPullRequestsBuilder.run()) where it will be caught and logged as a failed build attempt.

Below is the Jenkins log where the SocketTimeoutException can be seen, followed by the build continuing to run anyway.

Build started (LIB Provisioning-Pull Requests-CI).
Oct 18, 2016 12:59:03 AM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder run
Build Start (LIB Provisioning-Pull Requests-CI).
Oct 18, 2016 12:59:03 AM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashRepository getTargetPullRequests
Fetch PullRequests (LIB Provisioning-Pull Requests-CI).
Oct 18, 2016 12:59:04 AM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashRepository isBuildTarget
invalid pull request response.
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Read timed out
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.getRequest(StashApiClient.java:262)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.getPullRequestComments(StashApiClient.java:109)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.isBuildTarget(StashRepository.java:284)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashRepository.getTargetPullRequests(StashRepository.java:75)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashPullRequestsBuilder.run(StashPullRequestsBuilder.java:32)
    at stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run(StashBuildTrigger.java:299)
    at hudson.triggers.Trigger.checkTriggers(Trigger.java:273)
    at hudson.triggers.Trigger$Cron.doRun(Trigger.java:222)
    at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:50)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Read timed out
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:206)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient.getRequest(StashApiClient.java:254)
    ... 15 more
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:170)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
    at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
    at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
    at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
    at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
    at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
    at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient$1.call(StashApiClient.java:230)
    at stashpullrequestbuilder.stashpullrequestbuilder.stash.StashApiClient$1.call(StashApiClient.java:221)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    ... 1 more

Oct 18, 2016 12:59:19 AM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashRepository isBuildTarget
Building PR: 18
Oct 18, 2016 12:59:26 AM INFO stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger run

Plugin version 1.7.0 Jenkins version 2.7.4

cc: @nemccarthy

InformationOverload commented 7 years ago

Jenkins ver 2.32.1 (previously also seen on Jenkins 1.164.1) I am actually getting this same traceback, but I am getting it ONLY when running versions 1.6.0 and 1.7.0 If I back up to 1.5.3 then I do not get this traceback. Also, my pull requests are NOT even building If I have a PR change, either a commit or the test this please phrase, then I get the "Read timed out" stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger.run() failed for hudson.model.FreeStyleProject@79aa4ed3[MY_PullRequests] java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Read timed out

InformationOverload commented 7 years ago

Examining this issue further I can characterize the issue a little further: This occurs mostly on projects where we have a fair number of PR's with some fairly extensive review comments. For example, we currently have ~ 9 PR's outstanding Some are fairly new with few comments, but others are older It is taking > 30 Secs to parse through the information. Last time it only completed getting 7 of the 9 PR's information It crapped out while doing the 8th I see the following: PR-GET-REQUEST:https://\<stashhost>/rest/api/1.0/projects/\<ourProject>/repos/\<ourRepo>/pull-requests/435/merge But there IS no PR-GET-RESPONSE like there was for the previous 7 PR's And a tcpdump capture shows RST packets on the connection.

So another question might be: Is the timeout configurable?

salla2 commented 6 years ago

is this issue fixed? my jenkins version is 2.7.5 ... can we increase timeout?