Mahesh
Mahesh

Reputation: 1

I am getting failed to make TCP connection to port 8080: connection refused

10:07:34.779: [APP/PROC/WEB.0] * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit) 10:08:34.562: [HEALTH.0] Failed to make TCP connection to port 8080: connection refused 10:08:34.562: [CELL.0] Timed out after 1m0s: health check never passed.

Though my code is working fine on local machine

class Health (Resource):#this piecc of code is to perform the health check of the application so that it can run successfully without crashing on cf
      def get(self):
        return "UP"

api.add_resource(Health, '/health')

if __name__ == '__main__': #read about uses of main
    app.run(port = '8080')

Upvotes: 0

Views: 5435

Answers (1)

Daniel Mikusa
Daniel Mikusa

Reputation: 15006

You need to make sure you're listening on something other than 127.0.0.1/localhost. That is not externally accessible so health checks and external traffic won't be able to access your app if you are only listening on 127.0.0.1/localhost.

The easiest way is to listen on 0.0.0.0, which listens on all interfaces. You could technically listen on a specific IP, but that's more work and it ends up doing the same thing.

In my Python Flask apps which I run on Cloud Foundry, I end up doing something like this:

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5001)))

The second part is not technically necessary as PORT should always resolve to 8080, but that could change in the future so reading the PORT env variable is a good idea.

Hope that helps!

Upvotes: 3

Related Questions