jeremyevans/roda

Threading with http IO

Closed this issue · 2 comments

I am using roda and experiencing some issues within an endpoint where I want to call some external apis using threads. I have linked a repo displaying the behavior I am seeing and what I expect.

In the http_IO endpoint I am expecting to make the http call in a thread and have the result returned back to me. I am allowing the thread to work for up to 25 seconds before returning. However, the endpoint returns immediately and does not return the value from the thread. The call to join which should block is ignored and the status of the thread is sleep upon exit.

https://gitlab.com/michaelginalick/roda-threading-app/tree/master

I tried your example and it is returning the result of the thread for me. The returned value I see is [<RestClient::Response 200 "[\n {\n \"...">]. If you change your code to use:

thread << Thread.new { RestClient.get("https://jsonplaceholder.typicode.com/posts").body }

Then I see the body for the request (about 30KB of data). I tried with Webrick, Puma, and Unicorn and got the same results with each. So this doesn't appear to be a bug to me. Is there something I'm missing?

I notice your Gemfile lists thin. thin is based on eventmachine and doesn't handle internal threads. Please switch to a different Ruby webserver and the problem should disappear.