Possible to create duplicate Jira issue keys for the same build result in BRS_LINKEDJIRAISSUES with asynchronous calls to the result comment API

XMLWordPrintable

    • 3
    • Severity 2 - Major
    • 2

      Summary

      It's possible to to create duplicate Jira issue keys for the same build result in BRS_LINKEDJIRAISSUES with asynchronous calls to the result comment API. These duplicates will break the build expiry process.

      Steps to Reproduce

      Install seq and parallel and run this:

      BAMBOO_USER=
      BAMBOO_PASS=
      BAMBOO_URL=http://localhost:8085
      BUILD_RESULT_KEY=
      seq 6 | parallel curl --user $BAMBOO_USER:$BAMBOO_PASS -H \'Content-Type: application/xml\' -X POST \"$BAMBOO_URL/rest/api/latest/result/$BUILD_RESULT_KEY/comment\" --data \'\<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?\>\<comment\>\<content\>JRA-123\</content\>\</comment\>\'
      
      • Or just chain about 6 curls together with &

      Expected Results

      All comments get added but only one row in BRS_LINKEDJIRAISSUES per unique Jira issue key for a single build result.

      Actual Results

      All comments are added but there are duplicate rows created in BRS_LINKEDJIRAISSUES:

      linkedjiraissue_id	buildresultsummary_id	jira_issue_key	jira_issue_link_type
      182616065	182255685	JRA-123	0
      182616067	182255685	JRA-123	0
      182616066	182255685	JRA-123	0
      182616068	182255685	JRA-123	0
      

      Build expiry fails when attempting to expire the result with the duplicate linked Jira issue keys:

      2019-02-07 00:00:00,118 ERROR [7-BuildExpiryBean:pool-13-thread-1] [BatchingBatch] HHH000315: Exception executing batch [java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`BRS_LINKEDJIRAISSUES`, CONSTRAINT `FK_rhamoijfnb7coquyeag9aj978` FOREIGN KEY (`BUILDRESULTSUMMARY_ID`) REFERENCES `BUILDRESULTSUMMARY` (`BUILDRESULTSUMMARY_ID`))], SQL: delete from BUILDRESULTSUMMARY where BUILDRESULTSUMMARY_ID=?
      2019-02-07 00:00:00,118 WARN [7-BuildExpiryBean:pool-13-thread-1] [SqlExceptionHelper] SQL Error: 1451, SQLState: 23000
      2019-02-07 00:00:00,220 ERROR [7-BuildExpiryBean:pool-13-thread-1] [SqlExceptionHelper] Cannot delete or update a parent row: a foreign key constraint fails (`BRS_LINKEDJIRAISSUES`, CONSTRAINT `FK_rhamoijfnb7coquyeag9aj978` FOREIGN KEY (`BUILDRESULTSUMMARY_ID`) REFERENCES `BUILDRESULTSUMMARY` (`BUILDRESULTSUMMARY_ID`))
      2019-02-07 00:00:00,220 WARN [7-BuildExpiryBean:pool-13-thread-1] [BuildExpiryBeanImpl] Unable to expire BAMBOO-BUILD-RESULT
      

      Workaround

      If it comes from an automation that adds comments via the API, try to add a delay between API calls to avoid the race condition.

            Assignee:
            Unassigned
            Reporter:
            Jeremy Owen
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: