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

Pool doesn't work #16

Closed
vpol opened this issue Aug 5, 2016 · 8 comments
Closed

Pool doesn't work #16

vpol opened this issue Aug 5, 2016 · 8 comments
Labels

Comments

@vpol
Copy link

vpol commented Aug 5, 2016

connection = await asyncpg.connect(host='host', user='user', password='password', database='database')

works fine

pool = await asyncpg.create_pool(host='host', user='user', password='password', database='database')

Traceback (most recent call last):
File "main.py", line 126, in
app = loop.run_until_complete(get_app())
File "uvloop/loop.pyx", line 1133, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:19911)
File "uvloop/future.pyx", line 123, in uvloop.loop.BaseFuture.result (uvloop/loop.c:93421)
File "uvloop/future.pyx", line 78, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:92960)
File "uvloop/task.pyx", line 128, in uvloop.loop.BaseTask._fast_step (uvloop/loop.c:98739)
File "main.py", line 23, in get_app
database='database')
File "/usr/local/lib/python3.5/site-packages/asyncpg/pool.py", line 103, in _init
con = await self._new_connection()
File "/usr/local/lib/python3.5/site-packages/asyncpg/pool.py", line 89, in _new_connection
**self._working_opts)
File "/usr/local/lib/python3.5/site-packages/asyncpg/connection.py", line 506, in connect
await connected
File "uvloop/future.pyx", line 218, in await (uvloop/loop.c:94725)
File "uvloop/task.pyx", line 186, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:99922)
File "uvloop/future.pyx", line 78, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:92960)
asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "user"

# coding=utf-8
import asyncio

import asyncpg
import uvloop
from aiohttp import web

loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)


async def get_app():
    app = web.Application()

    app['db1'] = await asyncpg.connect(host='host', user='user', password='password', database='database')

    app['db2'] = await asyncpg.create_pool(host='host', user='user', password='password', database='database')

    return app


app = loop.run_until_complete(get_app())

if __name__ == '__main__':
    web.run_app(app, port=8083)

Am I doing something wrong?

@elprans
Copy link
Member

elprans commented Aug 5, 2016

@vpol Please make sure you specify valid values for the connection arguments. The database is rejecting your connection attempt.

@vpol
Copy link
Author

vpol commented Aug 5, 2016

I'm using same values in both cases.

@elprans
Copy link
Member

elprans commented Aug 5, 2016

I cannot reproduce this with the example you posted. The traceback doesn't seem to match it either. Please post the output you get from running the above code. Thanks.

@1st1
Copy link
Member

1st1 commented Aug 5, 2016

@vpol Can you reproduce the problem with max_size=1? And with max_size=2?

@vpol
Copy link
Author

vpol commented Aug 5, 2016

# coding=utf-8
import asyncio

import asyncpg
import uvloop
from aiohttp import web

loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)


async def get_app():
    app = web.Application()

    host = '127.0.0.1'
    user = 'username'
    password = 'password'
    database = 'database'

    conn = await asyncpg.connect(host=host, user=user, password=password, database=database)

    async with conn.transaction():
        result = await conn.fetchrow('select version()')
        print(result['version'])

    pool = await asyncpg.create_pool(host=host, user=user, password=password, database=database)

    async with pool.acquire() as connection:
        async with connection.transaction():
            result = await conn1.fetchrow('select version()')
            print(result['version'])

    return app


app = loop.run_until_complete(get_app())
➜  sample git:(master) ✗ python3 test2.py
PostgreSQL 9.5.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16), 64-bit
Traceback (most recent call last):
  File "test2.py", line 36, in <module>
    app = loop.run_until_complete(get_app())
  File "uvloop/loop.pyx", line 1133, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:19911)
  File "uvloop/future.pyx", line 123, in uvloop.loop.BaseFuture.result (uvloop/loop.c:93421)
  File "uvloop/future.pyx", line 78, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:92960)
  File "uvloop/task.pyx", line 128, in uvloop.loop.BaseTask._fast_step (uvloop/loop.c:98739)
  File "test2.py", line 26, in get_app
    pool = await asyncpg.create_pool(host=host, user=user, password=password, database=database)
  File "/usr/local/lib/python3.5/site-packages/asyncpg/pool.py", line 103, in _init
    con = await self._new_connection()
  File "/usr/local/lib/python3.5/site-packages/asyncpg/pool.py", line 89, in _new_connection
    **self._working_opts)
  File "/usr/local/lib/python3.5/site-packages/asyncpg/connection.py", line 506, in connect
    await connected
  File "uvloop/future.pyx", line 218, in __await__ (uvloop/loop.c:94725)
  File "uvloop/task.pyx", line 186, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:99922)
  File "uvloop/future.pyx", line 78, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:92960)
asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "username"

@vpol
Copy link
Author

vpol commented Aug 5, 2016

Runs if I use:

pool = await asyncpg.create_pool(host=host, user=user, password=password, database=database, min_size=1, max_size=2)

Doesn't work at all if min_size is not set and max_size is set to 2. (Default min_size = 10??)
Fails with: ValueError: min_size is greater than max_size

Doesn't actually work if more than one connection needs to be acquired from the pool. Fails with same issue (password authentication failed).

elprans added a commit that referenced this issue Aug 5, 2016
Make sure that password does not get removed from initial connection
settings so that subsequent pool connections can reuse it properly.
@elprans
Copy link
Member

elprans commented Aug 5, 2016

Fixed. v0.5.3 is building and will be on PyPI soon. Thanks for the report!

@vpol
Copy link
Author

vpol commented Aug 5, 2016

Works fine now. Thanks!

@vpol vpol closed this as completed Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants