Heroku 无法启动 Dropwizard 应用程序 - 尽管它已启动

Heroku fails to start Dropwizard app - although it's started

Heroku 无法正确启动小型 Dropwizard 应用程序。然而,日志显示 Jetty 容器已启动并且 运行 在 Heroku 提供的端口上:org.eclipse.jetty.server.ServerConnector: Started

因此,Heroku 状态从 starting 变为 crashed。然后 Heroku 再次尝试并最终死于 "App boot timeout".

我该如何进一步诊断?

2020-04-02T16:00:37.000000+00:00 app[api]: Build succeeded
2020-04-02T16:00:39.313741+00:00 app[web.1]: INFO  [2020-04-02 16:00:39,257] io.dropwizard.assets.AssetsBundle: Registering AssetBundle with name: assets for path /assets/*
2020-04-02T16:00:39.313839+00:00 app[web.1]: INFO  [2020-04-02 16:00:39,295] io.federecio.dropwizard.swagger.SwaggerHostResolver: Setting host for swagger to aa77d0bc-c110-47f6-86bd-26f789393da5
2020-04-02T16:00:39.313872+00:00 app[web.1]: INFO  [2020-04-02 16:00:39,295] io.dropwizard.assets.AssetsBundle: Registering AssetBundle with name: assets for path /swagger-static/*
2020-04-02T16:00:39.314079+00:00 app[web.1]: WARN  [2020-04-02 16:00:39,296] io.dropwizard.jetty.setup.ServletEnvironment: Overriding the existing servlet registered with the name: assets
2020-04-02T16:00:39.952166+00:00 app[web.1]: INFO  [2020-04-02 16:00:39,880] io.dropwizard.server.ServerFactory: Starting open-data-smn
[...]
2020-04-02T16:00:40.355433+00:00 app[web.1]: INFO  [2020-04-02 16:00:40,313] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@77bb0ab5{/admin,null,AVAILABLE}
2020-04-02T16:00:40.355434+00:00 app[web.1]: INFO  [2020-04-02 16:00:40,319] org.eclipse.jetty.server.ServerConnector: Started open-data-smn@f19c9d2{HTTP/1.1}{0.0.0.0:41114}
2020-04-02T16:02:06.374564+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-02T16:02:06.453536+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-02T16:02:13.178022+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-04-02T16:02:13.183227+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-04-02T16:02:14.900977+00:00 app[web.1]: INFO  [2020-04-02 16:02:14,859] io.dropwizard.assets.AssetsBundle: Registering AssetBundle with name: assets for path /assets/*
2020-04-02T16:02:15.005957+00:00 app[web.1]: INFO  [2020-04-02 16:02:14,923] io.federecio.dropwizard.swagger.SwaggerHostResolver: Setting host for swagger to 385e560c-52cd-4239-94dd-8d7a2cc11993
2020-04-02T16:02:15.006049+00:00 app[web.1]: INFO  [2020-04-02 16:02:14,924] io.dropwizard.assets.AssetsBundle: Registering AssetBundle with name: assets for path /swagger-static/*
2020-04-02T16:02:15.015815+00:00 app[web.1]: WARN  [2020-04-02 16:02:14,924] io.dropwizard.jetty.setup.ServletEnvironment: Overriding the existing servlet registered with the name: assets
2020-04-02T16:02:15.829866+00:00 app[web.1]: INFO  [2020-04-02 16:02:15,778] io.dropwizard.server.ServerFactory: Starting open-data-smn
[...]
2020-04-02T16:02:16.433772+00:00 app[web.1]: INFO  [2020-04-02 16:02:16,401] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@77bb0ab5{/admin,null,AVAILABLE}
2020-04-02T16:02:16.433901+00:00 app[web.1]: INFO  [2020-04-02 16:02:16,407] org.eclipse.jetty.server.ServerConnector: Started open-data-smn@f19c9d2{HTTP/1.1}{0.0.0.0:40280}
2020-04-02T16:02:42.603642+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=open-data-smn.herokuapp.com request_id=c0b90d4d-56cb-4f89-9a10-e058c3082afd fwd="62.12.132.2" dyno= connect= service= status=503 bytes= protocol=https
2020-04-02T16:03:40.488419+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-02T16:03:41.814453+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=open-data-smn.herokuapp.com request_id=d93055b5-c12d-40e6-93db-2375b108b5c2 fwd="62.12.132.2" dyno= connect= service= status=503 bytes= protocol=https

原来在应用程序配置 YAML 文件中配置服务器端口是这样的

server:
    port: $PORT

似乎适用于 Spring 引导应用程序,但不适用于我的。对于 Dropwizard,唯一的(?)选项是根据 https://devcenter.heroku.com/articles/setting-the-http-port-for-java-applications#dropwizard.

Procfile 中将其作为 JVM 环境变量传递

因此,Dropwizard 应用确实启动了并且它确实绑定到一个端口——只是不是 Heroku web dyno 保留的端口。 dyno 等待某个套接字绑定到该端口并最终超时。