Skip to content

Fix connection closing issue in conncection pool #113

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: 0
- name: Build wheels
uses: pypa/cibuildwheel@v2.17.0
uses: pypa/cibuildwheel@v2.22.0
env:
CIBW_SKIP: "cp36-* cp37-* pp36-* pp37-*"
- uses: actions/upload-artifact@v4
Expand Down
9 changes: 4 additions & 5 deletions asyncmy/connection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class Connection:
return self._last_usage

async def ensure_closed(self):
"""Close connection without QUIT message."""
"""Send QUIT message and close connection."""
if self._connected:
send_data = i.pack(1) + B.pack(COM_QUIT)
self._write_bytes(send_data)
Expand Down Expand Up @@ -1099,10 +1099,9 @@ cdef class MySQLResult:
self.field_count = first_packet.read_length_encoded_integer()
await self._get_descriptions()

# Apparently, MySQLdb picks this number because it's the maximum
# value of a 64bit unsigned integer. Since we're emulating MySQLdb,
# we set it to this instead of None, which would be preferred.
self.affected_rows = 18446744073709551615
# MySQLdb used 18446744073709551615 to indicate an undefined state.
# We now use -1 for the same purpose to avoid overflow issues.
self.affected_rows = -1

def _read_ok_packet(self, first_packet):
ok_packet = OKPacketWrapper(first_packet)
Expand Down
4 changes: 2 additions & 2 deletions asyncmy/pool.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Pool(asyncio.AbstractServer):

while self._free:
conn = self._free.popleft()
conn.close()
await conn.ensure_closed()

async with self._cond:
while self.size > self.freesize:
Expand Down Expand Up @@ -133,7 +133,7 @@ class Pool(asyncio.AbstractServer):

elif self._recycle > -1 and self._loop.time() - conn.last_usage > self._recycle:
self._free.pop()
conn.close()
await conn.ensure_closed()

else:
self._free.rotate()
Expand Down
Loading