Lahiru Karunatilake
Lahiru Karunatilake

Reputation: 23

Intermitant failure of API through Secure Gateway

I'm getting a error when accessing Tririga OSLC api via secure gateway from my nodered instance in my bluemix space. The Tririga server is hosted in my office at Pune, India. Bluemix zone is US-South.

Error:

Error: socket hang up : cap-sg-prd-3.integration.ibmcloud.com:15343/tririga/oslc/spq/triAllParkingLotsQC?oslc.select=*&oslc.where=spi:cstSensorId=15 

SyntaxError: undefined:1 Error: socket hang up :  ^ Unexpected token E

There are no issues when access the URL with postman. Is this something to do with link speeds between two DCs? The speed test of the Bluemix gateway shows 200ms latency for both up and down links.

Some more information: I did a sample application to remove Tririga out of the question. At bottom you can see my sample node app code that runs on same Tririga server. I created a new destination in the gateway service and tried to access the api via NodeRed flow using the Gateway host and port for the new destination. This api too has the same issue.

Error: socket hang up : cap-sg-prd-3.integration.ibmcloud.com:17451/inventory

I see both console logs of the below server request '/inventory' printed in my on-premise server console.

var express = require('express');

// create a new express server
var app = express();

var inventories= [
  { city : 'Beijing', quantity : 1000},
  { city : 'Shanghai', quantity : 500},
  { city : 'Guangzhou', quantity : 1000},
  { city : 'Shenzhen', quantity : 800}
];

//Get the inventory data
app.get('/inventory', function(req, res) {
  console.log("Request received");
  res.send({"code":1000, "inventory":inventories});
  console.log("Request sent");
});

app.listen(8000, function() {
   //print a message when the server starts listening
  console.log("server started on 8000");
});

One more observation is that http://cap-sg-prd-3.integration.ibmcloud.com:17451/inventory can be accessed over browser or postman without any problem.

Upvotes: 0

Views: 263

Answers (1)

Lahiru Karunatilake
Lahiru Karunatilake

Reputation: 23

Thanks Galen. I figured out the cause. By adding keep-alive header I managed to resolve the issue. For being precise I added following to my Node Red function before calling URL.

[{"id":"ef815a6f.f94ed8","type":"function","z":"280728a8.c953b8","name":"Tririga session","func":"\nvar get_headers = flow.get(\"get_headers\");\n\nif (get_headers === null) {\n var sessionid = msg.headers['set-cookie'];\n msg.headers = {\"connection\":\"Keep-Alive: timeout=15, max=100\",\"cookie\":sessionid};\n flow.set(\"get_headers\",msg.headers);\n \n}\n\nmsg.statusCode = \"\";\nmsg._msgid = \"\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1697.9458847045898,"y":142.6542739868164,"wires":[["f110f408.7fc428"]]}]

Upvotes: 1

Related Questions