V
V
Vladimir Mirka2017-09-15 22:26:36
API
Vladimir Mirka, 2017-09-15 22:26:36

Why does the local Rails Server freeze when using the internal API?

There is an application on a local server with an API that sends a json file at ./api/v1/search/query.
I tried to send a request from the root page:
Net::HTTP.get(URI.parse(query))
Then, when it happens, either the page starts loading forever and shows a white screen, or it shows the result, and the same story on the next request. Actually, the question is, what am I doing wrong and is it possible in principle to do so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Andreev, 2017-09-16
@flexaccess

Locally, most likely, the application is launched in one thread, that is, until one request completes to the end, the second one waits.
It turns out that the first request creates a second request, and the first request waits until the second request is completed.
But the second request will not start running until the first one completes. And the application crashes on timeout.
Run another instance on a different port and with a different pid
rails s -p 3001 -P tmp/pids/server2.pid
and the corresponding address will be localhost:3001/...
Or try using a unicorn/passenger or something like that as a webserver.

R
Roman Mirilaczvili, 2017-09-16
@2ord

Most likely, the application does not "hang", but simply waits a long time for a response over the network and, in the end, will receive a Timeout:: Error error, which you need to be able to handle.
You need to make sure that the value of the query variable is generally a valid http://... and that the http service is available at the given URL. If this service is located outside the local subnet, then both network delays and the amount of data transmitted must be taken into account.
Also one of the children's mistakes in the application is to refer to itself, that is, recursively. In this case, the application will never exit the recursion, and as a result, the browser will give an error about the unavailability of the application after the time has elapsed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question