Failed to prepare TableSyncChunk plugin: Use of uninitialized value $args{"chunk_range"} in lc at pt-table-sync line 3055

Bug #897758 reported by Dario Minnucci
18
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Fix Released
High
Brian Fraser
Debian
Fix Released
Unknown

Bug Description

- --- ORIGINAL MAIL TO UPSTREAM ---

Hi,

I'm experiencing this issue when I try to sync tables using 'pt-table-sync'

# DELETE REPLACE INSERT UPDATE ALGORITHM START END EXIT DATABASE.TABLE
Failed to prepare TableSyncChunk plugin: Use of uninitialized value $args{"chunk_range"} in lc at
/usr/bin/pt-table-sync line 3055. while doing MYDB on MYHOST

I've found [0] on Maatkit bugtracker and seems to be the same issue. By applying the patch
recommended there, the issue seems to desapear.

So, can you confirm this issue is present on 'pt-table-sync' or is due to a breakage on my system
(maybe after upgrading to Perl 5.14)

Thanks in advance.

[0] http://code.google.com/p/maatkit/issues/detail?id=1296

- --- /ORIGINAL MAIL TO UPSTREAM ---

Dario Minnucci (midget)
tags: added: pt-table-sync
Revision history for this message
Dario Minnucci (midget) wrote :
Revision history for this message
Dario Minnucci (midget) wrote :

Fix uploaded to Debian unstable.

Changed in debian:
status: Unknown → Fix Released
tags: added: crash
Revision history for this message
Dario Minnucci (midget) wrote :

Hi Daniel,

This bug seems to still be present in version 2.0.2 (which I'm now packaging for Debian)

The patch we've discussed at IRC [0] seems to still fix the issue.

Regards,

[0] http://patch-tracker.debian.org/patch/series/view/percona-toolkit/1.0.1-3/000-pt-table-sync-use-of-uninitialized-value-3055.diff

Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

We need to Just Fix This. We can't rely on the precedence rules -- we need to use parens. This is also much better coding practice because it makes it obvious to humans too. The precedence rules of a function versus || are not clear to me.

Changed in percona-toolkit:
milestone: none → 2.0.3
status: New → Confirmed
importance: Undecided → High
assignee: nobody → Brian Fraser (fraserbn)
Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

Assigned to Brian. Brian, do you think you can find all places in the source code where we do something like this, and fix with explicit parens?

summary: Failed to prepare TableSyncChunk plugin: Use of uninitialized value
- $args{"chunk_range"} in lc at /usr/bin/pt-table-sync line 3055.
+ $args{"chunk_range"} in lc at pt-table-sync line 3055
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

brian: perl -wE 'my %some_hash = (); ()=lc($some_hash{yadda})' gives me that error on 5.14+, but not on 5.8.8 or 5.10.0
brian: Daniel: Also getting that warnings on 5.12

tags: added: perl-5.12 perl-5.14
Revision history for this message
Brian Fraser (fraserbn) wrote :

Hm.. I might need a sanity check here, but I can't seem able to find any other instances like this, after having searched basically all keywords. The one case that I thought might also be ambiguous, which goes something like ref $x ? @$x : $x, is always resolved correctly by ref's prototype. (Initially unexpected to me is that sub my_ref { return ref shift } say my_ref $x ? @$x : $x; my_ref parses differently than a normal ref call, because it lacks a (_) prototype. I have no idea why ref would have a prototype.)

Revision history for this message
fursten (msv-kth) wrote :

This bug exists in pt-online-schema-change as well, both in versions 1.0.1 and 2.0.2.

Use of uninitialized value $args{"chunk_range"} in lc at /usr/bin/pt-online-schema-change line 2869, <STDIN> line 1.

patch-tracker.debian.org is currently unavailable so I can't find the proposed patch, but a simple fix here is be to change line 2869 to:

  my $chunk_range = lc ($args{chunk_range} || 'open');

There seems to be some confusion regarding the cause of this bug. The core reason is the line:

use warnings FATAL => 'all';

which asks Perl to crash in many conditions, for example when an uninitialized value is used. Without this line the current line would function correctly. The added parenthesis makes || operate on the uninitialized value, not lc, and this is always is legal since the uninitialized value is considered a valid boolean but not a valid string.

An alternative fix would thus be to follow "use warnings FATAL => 'all';" on line 2712 with:

no warnings FATAL => 'uninitialized';

which switches of the "crashing" for the use of uninitialized values.

Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

We're going to keep the fatal warning (it prevents lots of bugs, although some like this one don't get caught) and make sure lc() is unambiguous. This will be fixed in the upcoming release.

Brian Fraser (fraserbn)
Changed in percona-toolkit:
status: Confirmed → Fix Committed
Changed in percona-toolkit:
status: Fix Committed → Fix Released
Revision history for this message
Benoît Decaudin (benoit-decaudin) wrote :

Still present in pt-table-sync 2.1.2. Shall I fill a new bug report?

Revision history for this message
Daniel Niedergesäß (daniel-niedergesaess) wrote :

Hi,

in the latest version, the Bug is still present:

Failed to prepare TableSyncChunk plugin: Use of uninitialized value in join or string at /usr/local/bin/pt-table-sync line 3954. while doing ......

Regards Daniel

Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-284

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.