playframework/play-samples

play-rest-java-sample 504 when call put api

pbdevnick opened this issue · 4 comments

This how you can reproduce this issue.

  • download the sample
  • compile and run the project
  • call the post and get api
  • now call the put api to modify the data
  • it will throw 504 error.
private Optional<PostData> modify(EntityManager em, Long id, PostData postData) throws InterruptedException {
        final PostData data = em.find(PostData.class, id);
        if (data != null) {
            data.title = postData.title;
            data.body = postData.body;
        }
        Thread.sleep(10000L);
        return Optional.ofNullable(data);
    }

I figure out that if I remove the Thread.sleep it just work fine.

But why it's not working the Thread.sleep?

The purpose of that sleep is to demo how the system behaves in case of a slow time to respond. See the commit when it was added.

The modify method or the sleep usage should include a disclaimer: "Don't do this! It's just here for demo/testing purposes."

Alright! agree with your suggestion for disclaimer.

But I have got one question, what if this is the actual case where api needs to do more work
and it will take around 10s to complete it.

Then this should not give the 504 error.

Then tune all the timeouts involved in the chain of invocations.

But if you have a request that takes that long you probably need to move the long-running task to a separate threadpool (or an actor, or...) and respond immediately with, for example 202 Acccpeted.

This is more a discussion than an actual issue. I suggest we continue in https://discuss.lightbend.com/