Issue
I wrote java Telegram bot using this api - https://github.com/rubenlagus/TelegramBots . I test it on my PC and it works good. So I decided to test it on Heroku, how ever, after 90sec working it crash (first 90 sec works well). Heroku log:
2018-07-09T08:01:45.000000+00:00 app[api]: Build succeeded
2018-07-09T08:01:46.940201+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=18914 -jar target/AllaBot-1.0.0.jar`
2018-07-09T08:01:49.163121+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-07-09T08:01:49.166682+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8
2018-07-09T08:03:17.028453+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2018-07-09T08:03:17.028604+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-07-09T08:03:17.121323+00:00 heroku[web.1]: Process exited with status 137
2018-07-09T08:03:17.140915+00:00 heroku[web.1]: State changed from starting to crashed
my Procfile:
web: java -Dserver.port=$PORT -jar target/AllaBot-1.0.0.jar
As I understand, I need to change port in my project, don't me? I try to use some tips from internet but they don't works for me.
Solution
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
The error tells us that you need to listen to the port that the heroku will give us. So let's do it
public class Bot extends TelegramLongPollingBot {
private static final String TOKEN = System.getenv("TOKEN");
private static final String BOT_USERNAME = System.getenv("BOT_USERNAME");
private static final String PORT = System.getenv("PORT");
public void onUpdateReceived(Update update) {
}
public String getBotUsername() {
return BOT_USERNAME;
}
public String getBotToken() {
return TOKEN;
}
public static void main(String[] args) {
ApiContextInitializer.init();
TelegramBotsApi api = new TelegramBotsApi();
try {
api.registerBot(new Bot());
} catch (TelegramApiRequestException e) {
e.printStackTrace();
}
try (ServerSocket serverSocket = new ServerSocket(Integer.valueOf(PORT))) {
while (true) {
Socket clientSocket = serverSocket.accept();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Answered By - Sergey Nik
Answer Checked By - David Goodson (JavaFixing Volunteer)