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

AsyncHttpClient doesn't handle errors #16436

Closed
yglukhov opened this issue Dec 22, 2020 · 0 comments
Closed

AsyncHttpClient doesn't handle errors #16436

yglukhov opened this issue Dec 22, 2020 · 0 comments

Comments

@yglukhov
Copy link
Member

Which causes all sorts of weird behaviors. E.g. the following sample demonstrates an infinite hang in case when server closes connection before sending all the data. Otherwise if client is the only async "thread" in the process, the client will occasionally fail with error "No handles or timers registered in dispatcher." with totally irrelevant stack trace.

import asynchttpserver, httpclient, asyncdispatch

proc startServer() {.async.} =
  proc cb(req: Request) {.async.} =
    let headers = { "Content-length": "15"} # Provide invalid content-length
    await req.respond(Http200, "Hello World", headers.newHttpHeaders())

  var server = newAsyncHttpServer()
  await server.serve(Port(5555), cb)

proc runClient() {.async.} =
  let c = newAsyncHttpClient(headers = {"Connection": "close"}.newHttpHeaders)
  let r = await c.getContent("http://127.0.0.1:5555")
  echo r

asyncCheck startServer()
waitFor runClient()
yglukhov added a commit to yglukhov/Nim that referenced this issue Jan 12, 2021
yglukhov added a commit to yglukhov/Nim that referenced this issue Jan 12, 2021
@Araq Araq closed this as completed in 4ae5207 Jan 14, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
narimiran pushed a commit that referenced this issue Apr 28, 2021
* Fixes #16436

* Comments addressed

(cherry picked from commit 4ae5207)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants