Search code examples
pythonherokucherrypy

Heroku Python Web process failed to bind to $PORT within 60 seconds - not the obvious


OK similar questions answered before with simple solution. Don't think this is the same. First is my code then is the log. I am using the provided PORT env variable but I still get this error.

if __name__ == "__main__":
    import sys
    print( 'HELLO %s' % str(sys.argv[1]))
    #import os
    import os
    port = os.environ['PORT']
    print(port)
    cherrypy.config.update({
                        'server.socket_port': int(port),
                       })
    cherrypy.quickstart(House())

Here comes the log

2016-06-28T20:23:08.801989+00:00 app[web.1]: HELLO 33860
2016-06-28T20:23:08.802004+00:00 app[web.1]: 33860
2016-06-28T20:23:08.802471+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Listening for SIGTERM.
2016-06-28T20:23:08.802622+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Listening for SIGUSR1.
2016-06-28T20:23:08.802790+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Listening for SIGHUP.
2016-06-28T20:23:08.802942+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Bus STARTING
2016-06-28T20:23:08.803132+00:00 app[web.1]: CherryPy Checker:
2016-06-28T20:23:08.803139+00:00 app[web.1]: The Application mounted at '' has an empty config.
2016-06-28T20:23:08.803140+00:00 app[web.1]: 
2016-06-28T20:23:08.803640+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Started monitor thread '_TimeoutMonitor'.
2016-06-28T20:23:08.803919+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Started monitor thread 'Autoreloader'.
2016-06-28T20:23:08.955231+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Serving on http://127.0.0.1:33860
2016-06-28T20:23:08.955533+00:00 app[web.1]: [28/Jun/2016:20:23:08] ENGINE Bus STARTED
2016-06-28T20:24:06.045442+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-28T20:24:06.045345+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Solution

  • OK there are a couple of gotchas on this one. By far the most common is not to use the port specified in the environment variable PORT. The second is to use localhost or 127.0.0.1 (or leave to default) the host you specify. Specifying the host as 0.0.0.0 fixed it for me.

    if __name__ == "__main__":
        import sys
        print( 'HELLO %s' % str(sys.argv[1]))
        import os
        import os
        port = os.environ['PORT']
        print(port)
        cherrypy.config.update({
                                'server.socket_host': '0.0.0.0',
                                'server.socket_port': int(port),
                               })
        cherrypy.quickstart(House())