I am shooting off 500 requests using AsyncHttpClients. What I am experiencing in executing the code is the processor immediately maxes out, after about 10 seconds I can see the network traffic happenning (watching system monitor) and then after that completes the cpu remains at 100% usage. If I wait long enough I will start to see "done" messages. Is there a bug in some of the async modules or am I doing something wrong?
Here's the code:
import httpclient
import asyncdispatch
proc test (i : int) : Future[string] {.async.} =
echo("request " & $i)
var client = newAsyncHttpClient()
var data = await client.request("https://some.server")
echo("done " & $i)
return data.body
for i in 1..500:
asyncCheck test(i)
runForever()
I am running Ubuntu 14.04 in a VM, FYI.
(BTW I was quite hesitant to sign up for an account for the forum because the site does not use ssl, but I did not know where else I could post this question)
I have another issue, the program fails for me with Error: unhandled exception: invalid http version, 010b1078"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">" [Exception]. As I see this error occurs in httpclient.nim, 219: it seems the server sends its respond without HTTP version header or httpclient doesn't see it. The server is Apache/2.2.4 on Windows. The text of response is "Your browser sent a request that this server could not understand." with HTML header "400 Bad Request". Opening the same address in a browser gives another respond with the status "HTTP/1.1 200 OK".
This is the same for just 1 request. And this is for HTTP, HTTPS request fails with Error: unhandled exception: SSL support is not available. Cannot connect over SSL. [Exception].
[...] HTTPS request fails with Error: unhandled exception: SSL support is not available. Cannot connect over SSL. [Exception].
compile with nim -d:ssl file
I think I've found the cause for server to respond differently to Nim's httpclient and to web-browsers: web-browser sends the request as "GET / HTTP/1.1", and Nim sends as "GET HTTP/1.1" (without path part). So it causes Apache to return 400 status.
The second issue remains: the program fails when receives response from the server, because of not seeing HTTP version header. Either Apache sends the page about 400 error without header, just HTML, or Nim's module doesn't handle it properly. I've echo'ed data in async.net, 194, there's just html without headers.
Unless you can give me another website which gives the same error?
Sorry, can't test different sites, I just tested eli's code.
Out of curiosity and as beginner in Nim, what tools or steps do you use to debug an issue like this?
I went wrong everywhere but at some point I realized that errors weren't handled in the async code. strace is a nice tool to see syscalls.