Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Script exited with status code 0

Not applicable

I am facing a issue while running nodejs script with request-replay module in APIGEE.I have referenced by including the dependencies.Earlier there was an issue "Cannot find module request-replay" which was fixed by referring.Now,I am facing error as ,

" *** Starting script *** Script ReqRep.js exited with status code 0 "

My ReqRes.js script goes as below.This is the same program given in the link https://github.com/IndigoUnited/node-request-replay/blob/master/README.md.Even the Node.js logs does not present any other useful information to fix the issue.Could not find any relevant links in community posts for similar issue.Please let me know what could be the issue.

var fs = require('fs');
var request = require('request');
var replay = require('request-replay');
 
// Note that the options argument is optional 
// Accepts the same options the retry module does and an additional 
// errorCodes array that default to ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT'] 
replay(request('http://google.com/doodle.png', function (err, response, body) {
    // Do things 
}), {
    retries: 10,
    factor: 3
})
.on('replay', function (replay) {
    // "replay" is an object that contains some useful information 
    console.log('request failed: ' + replay.error.code + ' ' + replay.error.message);
    console.log('replay nr: #' + replay.number);
    console.log('will retry in: ' + replay.delay + 'ms')
})
 			
0 13 952
13 REPLIES 13

Dear @RadhamaniRamadoss ,

Request - Replay is working as per design. As long as ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT'] are not raised it goes into // Do things logic and does nothing since no code is getting executed there.. That's the reason you see the message "" *** Starting script *** Script ReqRep.js exited with status code 0 ""

It's always good to test same in local machine before deploying same to Apigee Edge. To test the replays behaviour change your code to below...

var fs = require('fs');
var request = require('request');
var replay = require('request-replay');
// Note that the options argument is optional
// Accepts the same options the retry module does and an additional
// errorCodes array that default to ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT']
replay(request('http://googldsse.com/doodle.png', function (err, response, body) {
    // Do things
    // It's doing nothing here...
  
}), {
    retries: 10,
    factor: 3
})
.on('replay', function (replay) {
    // "replay" is an object that contains some useful information
    console.log('request failed: ' + replay.error.code + ' ' + replay.error.message);
    console.log('replay nr: #' + replay.number);
    console.log('will retry in: ' + replay.delay + 'ms')
})

You will see the console.log outputs and retries...

Cheers,

Anil Sagar

Both http://googldsse.com/doodle.png and http://google.com/doodle.png are not returning error in the default errorcodes array.They are returning null when I print console.log(err) under the request call.

When I print console.log(body),its printing HTTP 404 error.

So,I am still not able to test the replay event here.I am currently doing testing locally.

Did you test in local or apigee edge instance ?

Please find console output in my local machine for below code,

var fs = require('fs');
var request = require('request');
var replay = require('request-replay');
// Note that the options argument is optional
// Accepts the same options the retry module does and an additional
// errorCodes array that default to ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT']
replay(request('http://googldsdse.com/doodle.png', function (err, response, body) {
    // Do things
    console.log(response);
}), {
    retries: 10,
    errorCodes: ['NOTFOUND',
    'EADDRINFO',
    'ETIMEDOUT',
    'ECONNRESET',
    'ESOCKETTIMEDOUT',
    'ENOTFOUND'],
    factor: 3
})
.on('replay', function (replay) {
    // "replay" is an object that contains some useful information
    console.log('request failed: ' + replay.error.code + ' ' + replay.error.message);
    console.log('replay nr: #' + replay.number);
    console.log('will retry in: ' + replay.delay + 'ms')
})

1088-screen-shot-2015-09-04-at-62535-pm.png

I am testing in local only.I tried using the same code given by you now.

But no change in result....

1089-screenshot-reqrep.png

The response is so big to capture entire output.Hence given 'more' to show you sample of it.

Actually before posting the issue ,my earlier code showed correct output as shown by you.But suddenly it started returning "null" for console.log(err) for the same code.And I have no clue on this change in behaviour.

@RadhamaniRamadoss Seems like you are using windows, What version of Node.JS are you running ? Can you try once on linux or macosx ?

Yes....I am using Windows.Will try in Linux and update.

I tried in Linux.The version of node.js I am using is 0.10.40.But I got same response.Not the expected output.

Can you try with Node.JS - v0.12.2 ?

Even in v0.12.2,it has not worked.I have created an open issue in github repository under request-replay.

Not applicable

The idea of Node.js support in Edge was to make it possible to run an HTTP server that receives API calls as the "target" of a proxy. That's why most of the examples show the Node.js apps being written as an HTTP server.

When you deploy a Node.js app to Edge, at deployment time we start your script, and assuming that it eventually calls "http.createServer" and "listen," it will receive incoming API traffic like any HTTP server.

In your case, you have an app that's not an HTTP server. So, we start it when the proxy is deployed, and when it exits, we try to restart it -- assuming that it's an HTTP server that crashed. Edge will continue to restart it, with increasing delays, but if it continues to restart constantly we will stop trying, assuming that something is wrong with it. The best way to write something that runs for a long time is to make it an HTTP server.

So that's a long way of asking -- what are you trying to accomplish with this app?

@Greg Brail I am trying to use Nodejs as a proxy to send request to external HTTP service.I am using Nodejs just to avail its request-replay module.

I want to tryout retry scenario when network communication failure with external HTTP service.I first tried using javascript but its setTimeout option didnt work in Edge.Hence,tried using request-replay module in nodejs script.First I am trying to find out whether its working in local before uploading to edge.But in local itself,its not working for me.For Anil Sagar,the same program has worked.So,I am stuck up in this issue.

I got response for the issue raised in github under the request-replay module.

https://github.com/IndigoUnited/node-request-repla...

Looks like my router or ISP is intercepting and producing the result which is not as expected.Hence,this should work as expected if the router issue gets fixed.