Skip to content

PT-XXXX- fixed connection leak due to confusion on parent flag#1123

Open
marcelohpf wants to merge 1 commit intopercona:3.xfrom
marcelohpf:connection-leak-on-get-replicas
Open

PT-XXXX- fixed connection leak due to confusion on parent flag#1123
marcelohpf wants to merge 1 commit intopercona:3.xfrom
marcelohpf:connection-leak-on-get-replicas

Conversation

@marcelohpf
Copy link
Copy Markdown
Contributor

Introduces a new argument to Cxn to flag that connection should not be closed automatically with InactiveDestroy, while keep the parent argument for its current usage of topology parent (or connection source parent)

The code had two different purposes to the same argument "parent" - topology parent and process parent in fork scenarios leading to a leak when get_replicas was called multiple times (e.g. when waiting for replication delays).

None of the current percona toolkit bin/ scripts seems to use forking other than deadlock detection. None of the "parent => X" cases were properly used in a multiprocess scenario, even when daemonizing the tool, connections were created after the fork;

You can reproduce it by:

  • create large enough table;
  • start dev environment mysqls
  • trigger OSC:
./bin/pt-online-schema-change \
  'D=mysqlslap,t=t1' --alter "ADD COLUMN mycolumn varchar(255) NOT NULL DEFAULT ''" \
  --execute --no-version-check --statistics --no-check-alter --recurse 2 --max-lag 10 \
  --chunk-size 10 --progress time,30  \
  --recursion-method dsn=D=percona,t=dsns \ # important
  --no-check-replication-filters \
  --database mysqlslap --host 127.0.0.1 \
  --user msandbox --password msandbox --port 12345

Then connect to one of the read-replicas and watch process list grow indefinitely:

while true; do 
  mysql -h 127.0.0.1 -P 12346 -u msandbox -pmsandbox -e 'show processlist;'
  sleep 1;
done

The root cause of the issue is that InactiveDestroy prevent dbh closing connection as part of the DESTROY workflow that is triggered when object looses reference count.

# other code
my $dbh;
{
  $dbh = DBI::connect();
   $dbh -> {InactiveDestroy} = 1;
  fork();
  if (is children) {
     $dbh->ping();  # ok
     exit;
  }
}
$dbh->ping() # should not fail because InactiveDestroy = 1; else it would
  • The contributed code is licensed under GPL v2.0
  • Contributor Licence Agreement (CLA) is signed
  • util/update-modules has been ran
  • Documentation updated
  • Test suite update

Introduces a new argument to Cxn to flag that connection should not be closed automatically with InactiveDestroy. The code had two different purposes to the same argument - replication topology parent and processes parent in fork scenarios leading to a leak.
@marcelohpf marcelohpf requested a review from svetasmirnova as a code owner May 8, 2026 07:23
@it-percona-cla
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Marcelo Ferreira seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants