@@ -829,8 +829,10 @@ function dumpSarifFile(
829829 fs . writeFileSync ( outputFile , sarifPayload ) ;
830830}
831831
832- const STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1000 ;
833- const STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1000 ;
832+ // Should lead to status checks after 5s, 15s, 35s, 75s, and 155s.
833+ const STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS = 5 * 1000 ;
834+ const STATUS_CHECK_BACKOFF_MULTIPLIER = 2 ;
835+ const STATUS_CHECK_MAX_TRIES = 5 ;
834836
835837type ProcessingStatus = "pending" | "complete" | "failed" ;
836838
@@ -854,12 +856,16 @@ export async function waitForProcessing(
854856 try {
855857 const client = api . getApiClient ( ) ;
856858
857- const statusCheckingStarted = Date . now ( ) ;
858- while ( true ) {
859- if (
860- Date . now ( ) >
861- statusCheckingStarted + STATUS_CHECK_TIMEOUT_MILLISECONDS
862- ) {
859+ // Do an initial wait because processing will always take a minimum of 2-3 seconds
860+ let statusCheckBackoff = STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS ;
861+ await util . delay ( statusCheckBackoff , { allowProcessExit : false } ) ;
862+
863+ for (
864+ let statusCheckingCount = 0 ;
865+ statusCheckingCount <= STATUS_CHECK_MAX_TRIES ; // Aborts on the last loop iteration
866+ statusCheckingCount ++
867+ ) {
868+ if ( statusCheckingCount === STATUS_CHECK_MAX_TRIES ) {
863869 // If the analysis hasn't finished processing in the allotted time, we continue anyway rather than failing.
864870 // It's possible the analysis will eventually finish processing, but it's not worth spending more
865871 // Actions time waiting.
@@ -868,6 +874,7 @@ export async function waitForProcessing(
868874 ) ;
869875 break ;
870876 }
877+
871878 let response : OctokitResponse < any > | undefined = undefined ;
872879 try {
873880 response = await client . request (
@@ -912,9 +919,8 @@ export async function waitForProcessing(
912919 util . assertNever ( status ) ;
913920 }
914921
915- await util . delay ( STATUS_CHECK_FREQUENCY_MILLISECONDS , {
916- allowProcessExit : false ,
917- } ) ;
922+ statusCheckBackoff *= STATUS_CHECK_BACKOFF_MULTIPLIER ;
923+ await util . delay ( statusCheckBackoff , { allowProcessExit : false } ) ;
918924 }
919925 } finally {
920926 logger . endGroup ( ) ;
0 commit comments