Heroku Java application timing out after 90 seconds

Tags: ,



I have been trying to host a discord bot on heroku for some time now. I Have everything set up now but the connection keeps timing out after 90 seconds because it cannot sustain a connection and I am not sure what is wrong.

Procfile: web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot

Error log:

2020-07-17T17:54:47.513540+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=7699 -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot`
2020-07-17T17:54:49.238091+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-07-17T17:54:49.241547+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-07-17T17:54:50.386750+00:00 app[web.1]: 938 [main] INFO net.dv8tion.jda.api.JDA - Login Successful!
2020-07-17T17:54:50.526175+00:00 app[web.1]: 1078 [JDA MainWS-WriteThread] INFO net.dv8tion.jda.internal.requests.WebSocketClient - Connected to WebSocket
2020-07-17T17:54:50.862291+00:00 app[web.1]: 1414 [JDA MainWS-ReadThread] INFO net.dv8tion.jda.api.JDA - Finished Loading!
2020-07-17T17:56:18.105532+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2020-07-17T17:56:18.120426+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-07-17T17:56:18.198101+00:00 heroku[web.1]: Process exited with status 137
2020-07-17T17:56:18.243205+00:00 heroku[web.1]: State changed from starting to crashed

I have been told to change the dyno in my procfile to anything OTHER then web but while the build succeeds, the bot never goes online if I were to use something like bot.

This post tells me to call a listen() method but I think this was either written for python or it is part of a library I do not know about.

My application is pretty short considering I am just focused on getting it hosted:

package com.marcuzzo.JDABot;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;

public class Bot {

    public static void main (String[] args) {

        int port = Integer.parseInt(System.getenv("PORT"));
    //  String host = "0.0.0.0";
        
        String token = "insert token here";
        try {
            JDA jda = JDABuilder.createDefault(token).build();
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

I am not sure if there is a certain method in the JDA library I am using that would solve this problem but I have not found any so far.

Answer

Looks like your bot is not web app. You should use worker heroku configuration. Please check https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku



Source: stackoverflow