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

A client hang indefinitely if the server never reply #669

Closed
avandecreme opened this issue Oct 1, 2012 · 6 comments
Closed

A client hang indefinitely if the server never reply #669

avandecreme opened this issue Oct 1, 2012 · 6 comments
Assignees
Milestone

Comments

@avandecreme
Copy link

Here is a small example:

Server side:

public class DummyServerResource extends ServerResource {

    @Get
    public String retrieve() {
        System.exit(0);
        return "Dummy";
    }
}

Client side:

    public static void main(String[] args) throws IOException {
        Client client = new Client(Protocol.HTTP);
        ClientResource cr = new ClientResource("http://localhost:8182/resttest/dummy");
        cr.setNext(client);
        Representation get = cr.get();
        System.out.println(get.getText());
    }

Looking in the ConnectionController class, I found a possible explication for the issue. The selectKeys method has a sleepTime parameter which is never used.
If I use it as a parameter of the select method, it seems to fix the problem:

        int selectCount = getSelector().select(sleepTime);

But this line has been modified on purpose on July to reduce CPU consumption, so I guess it is not a valid fix.

@avandecreme
Copy link
Author

Ok, it may be related to issue #659
I will try the suggested patch.

@jlouvel
Copy link
Member

jlouvel commented Oct 4, 2012

Nice, let me know if it helps!

@avandecreme
Copy link
Author

Good news, that fixes the problem.

Here is my final client code:

    public static void main(String[] args) throws IOException {
        Context context = new Context();
        context.getParameters().add("controllerSleepTimeMs", "5000");
        context.getParameters().add("maxIoIdleTimeMs", "5000");
        Client client = new Client(context, Protocol.HTTP);
        ClientResource cr = new ClientResource("http://localhost:8182/resttest/dummy");
        cr.setNext(client);
        Representation get = cr.get();
        System.out.println(get.getText());
    }

I had to set both controllerSleepTimeMs and maxIoIdleTimeMs parameters to 5000 to get the client crash in 14 seconds.

One remark is that the documentation here: http://www.restlet.org/documentation/2.1/jse/engine/org/restlet/engine/connector/BaseHelper.html says that the default value for controllerSleepTimeMs is 1 whereas it is 60000.
I am not sure if it is the code or the doc who is wrong.

@ghost ghost assigned jlouvel Oct 4, 2012
@jlouvel
Copy link
Member

jlouvel commented Oct 5, 2012

Thanks for the feedback. I'll fix the doc when applying the #659 patch as the sleep time changed from the previous value documented.

@jlouvel
Copy link
Member

jlouvel commented Oct 14, 2012

I've just fixed the documentation and applied the #659 patch.

@jlouvel jlouvel closed this as completed Oct 14, 2012
@avandecreme
Copy link
Author

Great.
I tried to use the maven SNAPSHOT from here: http://maven.restlet.org/org/restlet/jse/org.restlet/2.1-SNAPSHOT/ but it doesn't contain the update.
When are the snapshots published?

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