Hosted Target - 500 Server Error

wottinger
Participant II

I'm getting a 500 - Error when testing the URL: http://trhc-dev.apigee.net/v1/hello-hosted-targets-deploy-test

The Edge Management console UI says the hosted target is deployed to dev.

The message within the browser is:

"Error: Server Error The server encountered an error and could not complete your request.

Please try again in 30 seconds."

I have attempted to retry for approximately an hour an a half.

Looking at the runtime logs, it doesn't look like the hosted target node app has started. Not seeing the "'Node HTTP server is listening'" message in the runtime logs.

Solved Solved
0 24 1,240
1 ACCEPTED SOLUTION

Hey William,

Apologies about this issue. If we're seeing the same runtime logs for the proxy that isn't working it likely means that it didn't rebuild on the undeploy/redeploy cycle. I'll try to reproduce more thoroughly once I get into the office but for future reference a good way to guarantee a rebuild is to modify the code by adding a comment. This helps because we compare the sha of the proxy bundle to determine if there is new content and only rebuild if there's a difference. As the root of issue was upstream from us I'm not sure if a redeploy is sufficient or if a rebuild is also required.

View solution in original post

24 REPLIES 24

What port is your application listening on? Looking at your logs, it says that the your container is failing or it's listening on a bad port.

Within the app.yaml I've set an environment variable named PORT with a value of 5000.

That's not how it works. Hosted Targets tells you what port to listen on and you get it from process.env.PORT. Please see the documentation: https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-tutorials#devsite-back-to-top-hea...

I'm using the code from sample app from the tutorial. Currently listenting to process.env.PORT when the application starts.


var http = require('http');
console.log('node.js application starting...');
console.log(process.env);
var svr = http.createServer(function(req, resp) {
  console.log(req.method, req.url);
  resp.setHeader("Content-Type", "application/json");
  resp.end(JSON.stringify({ date: new Date(), msg: 'Hello, World!'}));
});
svr.listen(process.env.PORT || 5000, function() {
  console.log('Node HTTP server is listening');
});

Where in the logs do you see that logs it says that the container is failing or it's listening on a bad port?

The problem is you shouldn't set PORT in app.yaml. That's overriding the port we're setting.

I had the app looking at process.env.PORT to begin with and only added the PORT env variable after I received the 500 error. Ive removed it. Still not working. Ive undeployed the proxy and deleted the proxy. Going to try from scratch. Wish I had more signal in the logs. Oh well.

So, now I have attempted to go through the "Deploy Node.js from your system to Edge" tutorial within https://docs.apigee.com/api-platform/hosted-targets/hosted-targets-tutorials and deployed. When clicking the http://trhc-dev.apigee.net/node-hosted-express test url. I get the same error message:

Error: Server Error

The server encountered an error and could not complete your request.

Please try again in 30 seconds.

Here is the index.js:


var express = require('express') var app = express() app.get('/', function(req, res) { res.json({ hello: 'Hello World!' }) }) app.get('/hello/:name', function(req, res) { var name = req.params.name res.json({ hello: 'hello ' + name }) }) var server = app.listen(process.env.PORT || 9000, function() { console.log('Listening on port %d', server.address().port) })


Here is the package.json


{
  "name": "node-hosted-express",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js --use_strict"
  },
  "author": "",
  "license": "",
  "dependencies": {
    "express": "^4.16.0"
  }
}


Here is the app.yaml:

runtime: node
runtimeVersion: 8
application: node-hosted-express
env:
  - name: NODE_ENV
    value: production
  - name: LOG_LEVEL
    value: 3
<br>
	

I can reproduce this, but I'm not sure about your environment. I'll do some digging and get back to you.

Thank you for the assistance, Jeremy. I appreciate it.

It looks like your proxy is working now, but all I see different between version 1 and 2 is the basepath change. Can you let me know what other changes you made?

I deleted the original proxy: http://trhc-dev.apigee.net/v1/hello-hosted-targets-deploy-test


However, Im having the same issues with (http://trhc-dev.apigee.net/node-hosted-express) isnt working. See my last two comments below.

It looks like an upstream change to GAE has affected how containers are run. We've reported this and it should be fixed soon. I'll update as soon as I know.

This should be fixed. Do you mind trying again and letting me know the results?

I have tried the following proxy (http://trhc-dev.apigee.net/node-hosted-express) and I am getting the same 500 Server Error.

Im attempting to undeploy from the Edge "dev" environment and then redeploy to the "dev" environment. I'll let you know how it goes.

I redeployed to the "dev" environment and and attempted to test the link to the proxy: http://trhc-dev.apigee.net/node-hosted-express. Same error.


Error: Server Error

The server encountered an error and could not complete your request.

Please try again in 30 seconds.

The latest items from the runtime logs were from yesterday afternoon:

Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0Usage: npm <command>
Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0where <command> is one of:
Oct 8, 2018 4:33:05 PMstdoutsvr.0access, adduser, audit, bin, bugs, c, cache, ci, cit,
Oct 8, 2018 4:33:05 PMstdoutsvr.0completion, config, create, ddp, dedupe, deprecate,

I attempted to create another hosted target. I have successfully deployed the following "hello world" tutorial hosted target "node-hosted-express2" using the apigeetool CLI:


apigeetool deployhostedtarget -o trhc -e dev -n node-hosted-express2 -b /node-hosted-express2 -u  ...

When clicking the proxy URL: http://trhc-dev.apigee.net/node-hosted-express2/v1 I am able to see the see the appropriate response.

If your container is failing to startup, it should be in the logs. Are you sure you've selected the appropriate environment in the logs list?

In regards to the "Deploy Node.js from your system to Edge" tutorial. Don't know if this helps but I originally attempted to deploy from my local dev environment using apigeetool to the "test" environment.

apigeetool deployhostedtarget -o trhc -e test -n node-hosted-express -b /node-hosted-express ...

And got the following error:

Error: Duplicate key com.apigee.messaging.config.beans.HostedTargetRegion@64dbbe2b

Went back to Edge, and saw the proxy and it was not deployed to test due to the error. I then attempted to redeploy to test using Edge and got the same error.

I then attempted to deploy to "dev" using Edge, and it deployed. However, when I attempted to tryout the proxy in the browser I got the


Error: Server Error

The server encountered an error and could not complete your request.

Please try again in 30 seconds.

Here is the Runtime Log for the "test" environment:

TimeLevelServerMessage
Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0Usage: npm <command>
Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0where <command> is one of:
Oct 8, 2018 4:33:05 PMstdoutsvr.0access, adduser, audit, bin, bugs, c, cache, ci, cit,
Oct 8, 2018 4:33:05 PMstdoutsvr.0completion, config, create, ddp, dedupe, deprecate,
Oct 8, 2018 4:33:05 PMstdoutsvr.0dist-tag, docs, doctor, edit, explore, get, help,
Oct 8, 2018 4:33:05 PMstdoutsvr.0help-search, hook, i, init, install, install-test, it, link,
Oct 8, 2018 4:33:05 PMstdoutsvr.0list, ln, login, logout, ls, outdated, owner, pack, ping,
Oct 8, 2018 4:33:05 PMstdoutsvr.0prefix, profile, prune, publish, rb, rebuild, repo, restart,
Oct 8, 2018 4:33:05 PMstdoutsvr.0root, run, run-script, s, se, search, set, shrinkwrap, star,
Oct 8, 2018 4:33:05 PMstdoutsvr.0stars, start, stop, t, team, test, token, tst, un,
Oct 8, 2018 4:33:05 PMstdoutsvr.0uninstall, unpublish, unstar, up, update, v, version, view,
Oct 8, 2018 4:33:05 PMstdoutsvr.0whoami
Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0npm <command> -h quick help on <command>
Oct 8, 2018 4:33:05 PMstdoutsvr.0npm -l display full usage info
Oct 8, 2018 4:33:05 PMstdoutsvr.0npm help <term> search for help on <term>
Oct 8, 2018 4:33:05 PMstdoutsvr.0npm help npm involved overview
Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0Specify configs in the ini-formatted file:
Oct 8, 2018 4:33:05 PMstdoutsvr.0/root/.npmrc
Oct 8, 2018 4:33:05 PMstdoutsvr.0or on the command line via: npm <command> --key value
Oct 8, 2018 4:33:05 PMstdoutsvr.0Config info can be viewed via: npm help config
Oct 8, 2018 4:33:05 PMstdoutsvr.0
Oct 8, 2018 4:33:05 PMstdoutsvr.0npm@6.4.1 /usr/local/lib/node_modules/npm
Oct 8, 2018 4:32:47 PMstdoutsvr.0
Oct 8, 2018 4:32:47 PMstdoutsvr.0where <command> is one of:
Oct 8, 2018 4:32:47 PMstdoutsvr.0access, adduser, audit, bin, bugs, c, cache, ci, cit,
Oct 8, 2018 4:32:47 PMstdoutsvr.0completion, config, create, ddp, dedupe, deprecate,
Oct 8, 2018 4:32:47 PMstdoutsvr.0dist-tag, docs, doctor, edit, explore, get, help,
Oct 8, 2018 4:32:47 PMstdoutsvr.0help-search, hook, i, init, install, install-test, it, link,
Oct 8, 2018 4:32:47 PMstdoutsvr.0list, ln, login, logout, ls, outdated, owner, pack, ping,
Oct 8, 2018 4:32:47 PMstdoutsvr.0prefix, profile, prune, publish, rb, rebuild, repo, restart,
Oct 8, 2018 4:32:47 PMstdoutsvr.0root, run, run-script, s, se, search, set, shrinkwrap, star,
Oct 8, 2018 4:32:47 PMstdoutsvr.0stars, start, stop, t, team, test, token, tst, un,
Oct 8, 2018 4:32:47 PMstdoutsvr.0uninstall, unpublish, unstar, up, update, v, version, view,
Oct 8, 2018 4:32:47 PMstdoutsvr.0whoami
Oct 8, 2018 4:32:47 PMstdoutsvr.0
Oct 8, 2018 4:32:47 PMstdoutsvr.0npm <command> -h quick help on <command>
Oct 8, 2018 4:32:47 PMstdoutsvr.0npm -l display full usage info
Oct 8, 2018 4:32:47 PMstdoutsvr.0npm help <term> search for help on <term>
Oct 8, 2018 4:32:47 PMstdoutsvr.0npm help npm involved overview
Oct 8, 2018 4:32:47 PMstdoutsvr.0
Oct 8, 2018 4:32:47 PMstdoutsvr.0Specify configs in the ini-formatted file:
Oct 8, 2018 4:32:47 PMstdoutsvr.0/root/.npmrc
Oct 8, 2018 4:32:47 PMstdoutsvr.0or on the command line via: npm <command> --key value
Oct 8, 2018 4:32:47 PMstdoutsvr.0Config info can be viewed via: npm help config
Oct 8, 2018 4:32:47 PMstdoutsvr.0
Oct 8, 2018 4:32:47 PMstdoutsvr.0npm@6.4.1 /usr/local/lib/node_modules/npm

Hey William,

Apologies about this issue. If we're seeing the same runtime logs for the proxy that isn't working it likely means that it didn't rebuild on the undeploy/redeploy cycle. I'll try to reproduce more thoroughly once I get into the office but for future reference a good way to guarantee a rebuild is to modify the code by adding a comment. This helps because we compare the sha of the proxy bundle to determine if there is new content and only rebuild if there's a difference. As the root of issue was upstream from us I'm not sure if a redeploy is sufficient or if a rebuild is also required.

Thank you Josh and Jeremy. As I mentioned in my last comment to Jeremy...

I attempted to create another hosted target. I have successfully deployed the following "hello world" tutorial hosted target "node-hosted-express2" using the apigeetool CLI:

apigeetool deployhostedtarget -o trhc -e dev -n node-hosted-express2 -b /node-hosted-express2 -u  ...

When clicking the proxy URL: http://trhc-dev.apigee.net/node-hosted-express2/v1 I am able to see the see the appropriate response.

Glad things are working now. Please let us know if you see any other issues. You were the first user to catch this bug and we appreciate the fast responses that helped us resolve it quickly.