Fix connection pool test_sqlor causing connection pileup under high concurrency

Remove test_sqlor() validation from SqlorPool.context() which was causing:
- Every request to test ALL idle connections with SELECT 1
- Healthy connections being incorrectly deleted due to timeout under load
- Race conditions when multiple requests test the same connection
- Excessive connection creation leading to 501 Sleep connections

The new logic takes the first available connection without validation.
If a connection fails during actual use, the exception propagates naturally.
This commit is contained in:
yumoqing 2026-06-27 14:19:24 +08:00
parent f6c6b4d913
commit a2ef1bc48a

View File

@ -118,12 +118,8 @@ class SqlorPool:
yielded_sqlor = None
for s in sqlors:
if not s.used:
flg = await self.test_sqlor(s.sqlor)
if flg:
yielded_sqlor = s
else:
await self._del_sqlor(s.sqlor)
self.sqlors = [ x for x in self.sqlors if x != s ]
yielded_sqlor = s
break # Take first available connection without testing
if not yielded_sqlor:
yielded_sqlor = await self._new_sqlor()
yielded_sqlor.used = True