【发布时间】:2019-02-12 19:44:46
【问题描述】:
我有一个部署在 Heroku 上的 Java 应用程序。部署就像一个魅力,没有错误或警告,应用程序开始工作。但是,一段时间后,我收到以下错误:
错误 R10(启动超时)-> Web 进程在启动后 90 秒内未能绑定到 $PORT
我在本地运行我的应用程序时没有收到任何错误。
仅供参考:此应用程序会定期检查是否对 postgresql 数据库中的表进行了更改,如果是,则更新同一数据库中的另一个表(据我所知没有真的与我的问题相关,但给你)。
这是日志:
2019-02-12T19:37:15.444651+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=24637 -cp target/classes:target/dependency/* com.name.numbersbackend.Main`
2019-02-12T19:37:18.657701+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2019-02-12T19:37:18.660650+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2019-02-12T19:37:35.580329+00:00 app[web.1]: .
2019-02-12T19:37:51.105807+00:00 app[web.1]: .
2019-02-12T19:38:06.683974+00:00 app[web.1]: .
2019-02-12T19:38:22.198062+00:00 app[web.1]: .
2019-02-12T19:38:37.792613+00:00 app[web.1]: .
2019-02-12T19:38:45.489753+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2019-02-12T19:38:45.489753+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-02-12T19:38:45.663859+00:00 heroku[web.1]: Process exited with status 137
2019-02-12T19:38:45.682773+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-12T19:38:45.766843+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-12T19:38:48.871480+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=39010 -cp target/classes:target/dependency/* com.name.numbersbackend.Main`
2019-02-12T19:38:51.074950+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2019-02-12T19:38:51.077995+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2019-02-12T19:39:07.724633+00:00 app[web.1]: .
2019-02-12T19:39:23.250203+00:00 app[web.1]: .
2019-02-12T19:39:38.760492+00:00 app[web.1]: .
2019-02-12T19:39:54.313859+00:00 app[web.1]: .
2019-02-12T19:40:09.881207+00:00 app[web.1]: .
2019-02-12T19:40:19.374407+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-12T19:40:19.187236+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2019-02-12T19:40:19.187351+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-02-12T19:40:19.354497+00:00 heroku[web.1]: Process exited with status 137
仅供参考:2019-02-12T19:39:38.760492+00:00 app[web.1]: . 行(以及类似的行)包含我的应用程序的一些临时输出,以表明它实际上正在做某事。对于这些行中的每一行,程序都会检查表是否有更改,如果有,是否需要采取行动(如果确实需要采取行动,则应用程序的输出更有意义)。
如您所见,应用程序正常启动,运行了一段时间,然后崩溃甚至重新启动。但是,在某些时候它会完全停止工作。
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.name</groupId>
<artifactId>com.name.app.backend</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
<dependency>
<groupId>com.github.myname</groupId>
<artifactId>app-lib</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
...和我的 Procfile:
web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes:target/dependency/* nl.limakajo.numbersbackend.Main
在 SO 上进行大量谷歌搜索和浏览后,我还没有找到解决方案。
【问题讨论】:
-
这个错误意味着从 Heroku 启动你的应用程序到它绑定到 $PORT 已经超过 90 秒。当您运行
heroku ps:restart时,应用程序开始接收网络请求通常需要多长时间?nl.limakajo.numbersbackend.Main类在绑定到端口之前做了什么? -
应用程序在连接到网络之前不会做太多事情。目前它每 15 秒连接一次(提醒自己:这应该不那么频繁)。
-
每 15 秒建立一个出站连接?但我指的是它在本地绑定到 $PORT 的时间。它应该在应用程序启动时立即执行一次。否则,它不应该是
web:进程。 -
也许它不应该是
web:进程。该应用程序所做的(如所述)是检查 postgresql 数据库并更新该数据库中的表(取决于所述数据库中的数据)。你有什么建议? -
把
web:改成worker:什么的。然后重新部署,运行heroku ps:scale worker=1