Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running port() returning 0 if called to quickly #1253

Open
weeryan17 opened this issue Feb 3, 2022 · 1 comment
Open

Running port() returning 0 if called to quickly #1253

weeryan17 opened this issue Feb 3, 2022 · 1 comment

Comments

@weeryan17
Copy link

When trying to get the port spark is actually listening on with the port being set to 0, it can return 0 if called too quickly.
This seams to be because the server is initializing in a separate thread and therefor not setting the port number to the actual port number before calling port().
See example

public int initWeb() {
    port(0);
    get("/thing", (req, res) -> ...);
    return port(); // returns 0
}

There also seams to be no way to check for the server being fully initialized as far as I can tell, but I could be wrong about that.

@weeryan17 weeryan17 changed the title Running port() returning 0 Running port() returning 0 if called to quickly Feb 3, 2022
@corbs-blis
Copy link

Try:
Spark.awaitInitialization();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants