question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Javalin.start() should throw if startup fails

See original GitHub issue

Actual behavior (the bug) I have another server occupying the port 8080. The Javalin.start() function completes successfully, but Javalin is not running.

Expected behavior Since start() is synchronous, I expect the start() function to throw an exception if Javalin fails to start (e.g. on BindException).

To Reproduce

  1. run netcat -l 8080
  2. start Javalin on port 8080: Javalin.create().start(8080).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Mar 7, 2019

I’d only suggest to add cause to the second throw - the , e part:

Thanks, missed that one. Fixed in https://github.com/tipsy/javalin/commit/10ebe08b8c10a390baeb0ad2cd607cc285eb1d91.

Wow, you’re really fast! Awesome work.

There’s been a lot of traffic the past few days because of the article in Java Magazine, so I’m trying to respond as quickly as possible 😃

1reaction
tipsycommented, Mar 6, 2019

What about:

} catch (Exception e) {
    log.error("Failed to start Javalin");
    eventManager.fireEvent(JavalinEvent.SERVER_START_FAILED);
    if (e.getMessage() != null && e.getMessage().contains("Failed to bind to")) {
        throw new RuntimeException("Port already in use. Make sure no other process is using port " + port + " and try again.", e);
    } else if (e.getMessage() != null && e.getMessage().contains("Permission denied")) {
        throw new RuntimeException("Port 1-1023 require elevated privileges (process must be started by admin).");
    }
    throw new RuntimeException(e);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Javalin.start() should throw if startup fails · Issue #492
I have another server occupying the port 8080. The Javalin.start() function completes successfully, but Javalin is not running. ... Since start() ...
Read more >
Documentation - Javalin - A lightweight Java and Kotlin ...
start() method spawns a user thread, starts the server, and then returns. Your program will not exit until this thread is terminated by...
Read more >
Validation improvements, Micrometer support, and a lot of ...
The validation added in 2.2.0 is one of Javalin's most popular ... if it failed to start, now it throws instead; sessionHandler() no...
Read more >
Running Javalin on GraalVM (22MB total size)
If the compiler decides to include this class, it will just do that and throw an error if the class is not found....
Read more >
Archive - v3 documentation
start() method spawns a user thread, starts the server, and then returns. Your program will not exit until this thread is terminated by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found