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

fix #166 (Got an error reading communication packets) for pool #987

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

parsapoorsh
Copy link

What do these changes do?

there is a problem for pool connections when the program exits even after using pool.wait_closed() it causes a ton of [Warning] Aborted connection 1 to db: 'database' user: 'user' host: '127.0.0.1' (Got an error reading communication packets) warning in mariadb (maybe mysql too).
the problem is in aiomysql/connection.py close function:

def close(self):
    """Close socket connection"""
    if self._writer:
        self._writer.transport.close()
    self._writer = None
    self._reader = None

async def ensure_closed(self):
    """Send quit command and then close socket connection"""
    if self._writer is None:
        # connection has been closed
        return
    send_data = struct.pack('<i', 1) + bytes([COMMAND.COM_QUIT])
    self._writer.write(send_data)
    await self._writer.drain()
    self.close()

the close function just replaces self._writer content with None, it does not send any close packets.
this causes the said warning.
just by using await conn.ensure_closed() instead of conn.close() in wait_closed() function in Pool, the problem goes away.

Are there changes in behavior for the user?

No.

Related issue number

Fixes #166

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

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

Successfully merging this pull request may close these issues.

Aborted connection
1 participant