0

I am executing multiple iterations of requests to AWS to fetch attributes of various buckets. On my local environment, the first few requests are initially returning with a status code 200 (OK), but thereafter, I encounter multiple status code 408 (Request Timeout) responses. However, in production, I do not experience any 408 errors and the requests are functioning as expected. Both the local and production environments are executing the same code and utilizing the same database. (My app is also hosted on AWS).

Here's my function that gets executed multiple times:

   function getS3VidSource(accidentVideoSource) {
        return new Promise((resolve, reject) => { 
            const vidData = {
                Bucket: accidentVideoSource.bucket,
                Key: accidentVideoSource.key
            };
    
            const vidDataStr = JSON.stringify(vidData);
    
            const getHeaders = {  
                'Content-Type': 'application/json',
                'Query' : vidDataStr
            };
    
            const getVideoLinkGet = {
                host: S3_TRAFFIC_VID_STREAMING_API_HOST,
                port: S3_TRAFFIC_VID_STREAMING_API_PORT,
                path: '/getVideoLink',
                method: 'GET',
                headers: getHeaders,
                timeout: 10000
            };
    
            const reqGet = http.request(getVideoLinkGet, (resp) => { 
    
                if(resp.statusCode == 200) {  
                    let body = ''; 
    
                    resp.setEncoding('utf8');
    
                    resp.on('data', (chunk) => { 
                        body += chunk;
                    });
    
                    resp.on('end', () => {  
                        resolve(JSON.parse(body));
                    });  
    
                } else {  
                    console.log('Get Video Stream Error code: '+ resp.statusCode +' Response: ' + JSON.stringify(resp.headers));  
                    reject(resp.statusCode); 
                } 
    
            });     
    
            reqGet.on('error', (err) => reject(err));   
            
            reqGet.write("");
            reqGet.end();
         });            
    }  

My console output:

.....
Get Video Stream Error code: 408 Response: {"connection":"close"}
Get Video Stream Error code: 408 Response: {"connection":"close"}
Get Video Stream Error code: 408 Response: {"connection":"close"}
Get Video Stream Error code: 408 Response: {"connection":"close"}
Get Video Stream Error code: 408 Response: {"connection":"close"}
Get Video Stream Error code: 408 Response: {"connection":"close"}
.....

I ran it in debug mode and noticed that the first hundred or so requests are OK but then after that it starts throwing 408's. Also added functionality to re-execute the request after a short delay if a status of 408 is received, but still no luck.

Any explanation as to why this is happening would be greatly appreciated.

CobusVon
  • 3
  • 3

0 Answers0