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

java.util.NoSuchElementException: No value present when using ZooKeeperUpdatingListener #933

Closed
liuzhengyang opened this issue Jan 1, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@liuzhengyang
Copy link

liuzhengyang commented Jan 1, 2018

Hi, I am new to armeria. I build a simple project using armeria 0.5.60 according to armeria documentation, everything goes well until using 'Service discovery with ZooKeeper'. I got this exception

java.util.NoSuchElementException: No value present
	at java.util.Optional.get(Optional.java:135)
	at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
	at com.linecorp.armeria.server.zookeeper.ZooKeeperUpdatingListener.serverStarting(ZooKeeperUpdatingListener.java:69)
	at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
	at com.linecorp.armeria.server.Server$StateManager.notifyState(Server.java:585)
	at com.github.liuzhengyang.server.Bootstrap.main(Bootstrap.java:38)
	at com.linecorp.armeria.server.Server$StateManager.enterStarting(Server.java:541)
Caused by: java.lang.IllegalStateException: failed to notify all server listeners
	at com.linecorp.armeria.server.Server.start(Server.java:250)
	at com.linecorp.armeria.server.Server$StateManager.enterStarting(Server.java:542)
	at com.linecorp.armeria.server.Server.start(Server.java:235)
	at com.linecorp.armeria.server.Server.start(Server.java:250)
	at com.github.liuzhengyang.server.Bootstrap.main(Bootstrap.java:38)
	at com.linecorp.armeria.server.Server.start(Server.java:235)
	... 1 more

And here is my example code.

public class Bootstrap {
    public static void main(String[] args) {

        ServerBuilder sb = new ServerBuilder();
        sb.port(8081, "http");

        sb.serviceUnder("/hello",
                        new GrpcServiceBuilder()
                                .addService(new MyHelloService())
                                .supportedSerializationFormats(GrpcSerializationFormats.values())
                                .enableUnframedRequests(true)
                                .build());
        sb.accessLogWriter(AccessLogWriters.common());

        sb.serviceUnder("/docs", new DocService());

        Server server = sb.build();

        ServerListener serverListener = new ZooKeeperUpdatingListener("localhost:2181", "/myProducionEndpoints", 1000);
        server.addListener(serverListener);

        server.start().join();
    }
}

If i remove the ServerListener, it works well. And i looked into com.linecorp.armeria.server.Server, found primaryActivePort is set in ServerPortStartListener, but ZooKeeperUpdatingListener.serverStarting is triggered before ServerPortStartListener added to Server start future listeners.

Did I miss something?
I am not sure whether I explained this problem clear or not. Thanks in advance.

@trustin
Copy link
Member

trustin commented Jan 2, 2018

Thanks for reporting! Let me take a look and get back to you soon.

@trustin
Copy link
Member

trustin commented Jan 2, 2018

Indeed. The access to the active ports should be done in serverStarted, not in serverStarting. Let me send a fix PR.

trustin added a commit to trustin/armeria that referenced this issue Jan 2, 2018
Motivation:

ZooKeeperUpdatingListener attempts to access `Server.activePort()` in
`serverStarting()`. `Server.activePort()` is supposed to be available in
`serverStarted()`.

Modifications:

Use `serverStarted()` rather than `serverStarting()`.

Result:

- Fixes line#933
@trustin trustin added the defect label Jan 2, 2018
@trustin trustin self-assigned this Jan 2, 2018
@trustin trustin added this to the 0.56.1 milestone Jan 2, 2018
trustin added a commit that referenced this issue Jan 2, 2018
Motivation:

ZooKeeperUpdatingListener attempts to access `Server.activePort()` in
`serverStarting()`. `Server.activePort()` is supposed to be available in
`serverStarted()`.

Modifications:

Use `serverStarted()` rather than `serverStarting()`.

Result:

- Fixes #933
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this issue Sep 19, 2020
Motivation:

ZooKeeperUpdatingListener attempts to access `Server.activePort()` in
`serverStarting()`. `Server.activePort()` is supposed to be available in
`serverStarted()`.

Modifications:

Use `serverStarted()` rather than `serverStarting()`.

Result:

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

No branches or pull requests

2 participants