noirello / bonsai

Simple Python 3 module for LDAP, using libldap2 and winldap C libraries.
MIT License
116 stars 32 forks source link

Avoid UnboundLocalError in AIOConnectionPool.spawn #71

Closed rra closed 1 year ago

rra commented 1 year ago

get() may fail with an exception and thus not return if the remote LDAP server is inaccessible and the pool has no idle connections, but spawn() unconditionally attempts to return the connection returned by get() to the pool in a finally block. This can result in an UnboundLocalError for conn, since the local variable is only created on successful return from get().

Handle this by initializing conn and not attempting to return it to the pool if it's still None.

noirello commented 1 year ago

Looks good. Thank you!