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

If making more requests then in a pool, odd errors happen. #9

Open
treeform opened this issue Oct 29, 2018 · 1 comment
Open

If making more requests then in a pool, odd errors happen. #9

treeform opened this issue Oct 29, 2018 · 1 comment

Comments

@treeform
Copy link

Pool size of 10 works, pool size of 5 does not.

import asyncdispatch, asyncpg/asyncpg

const POOL_SIZE = 5
var pool = newPool(POOL_SIZE)

proc main() {.async.} =
  var start: float
  var connStr = "host=localhost port=5432 dbname=test user="
  await pool.connect(connStr)
  var futures = newSeq[Future[apgResult]]()
  for i in 0..<10:
    futures.add exec(pool, "SELECT $1, pg_sleep(1);", i)
  var results = await all(futures)
  for res in results:
    for item in res[0].rows():
      echo item, " "

waitFor main()

Starts 10 connections that sleep for 10 seconds. If pool size is less the number of connections strange error happens:

asyncpgtest.nim(18)      asyncpgtest
asyncdispatch.nim(1654)  waitFor
asyncdispatch.nim(1514)  poll
asyncdispatch.nim(1233)  runOnce
Error: unhandled exception: No handles or timers registered in dispatcher. [ValueError]

I think if connections are not available it should error out or wait some how. I think it just forgets to register no available connection case.

Nim Compiler Version 0.19.1 [MacOSX: amd64]
Compiled at 2018-10-22
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 16c3d4332fac56b275ca3c66dcf12573738bdc91
active boot switches: -d:release
@treeform
Copy link
Author

I ended up writing my own async pg lib that does not have this issue here: https://github.com/treeform/pg

@treeform treeform reopened this Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant