Perl: Net::MySQL “packets out of order”

Found another issue with Net::MySQL (after this one). Why are we using that again? Ah yes, it’s pure Perl and we hate compiling modules. Well, you get what you pay for.

When inserting a lot of data it is better to create one huge insert statement then thousands of small ones. When you do that you have to make sure that your server accepts huge amounts of data by setting an appropriate value for max_allowed_packet.

Furthermore the MySQL protocol defines a “MySQL packet” to have a header of three bytes for the length followed by a one byte counter. The packet body starts with one byte command followed by data (a SQL query or response). With three bytes you can count up to around 16 million or in other words a MySQL packet can only be 16MB long (plus four header bytes), because that is the maximum value for the length field.

What Net::MySQL does in this case is: nothing. It sets a length value that is too big for three bytes, ignores the need for a counter and just keeps pouring data into the socket like there is no tomorrow without splitting into packets. The server reacts with a connection reset and “packets out of order” error. At least that is what we have observed.

I’ve sent a bug report and patch to Net::MySQL’s bug tracker.

  • email
  • PDF
  • Google Bookmarks
  • Yahoo! Bookmarks
  • del.icio.us
  • Twitter
  • Reddit
  • Digg
  • Ping.fm
  • Slashdot
  • Facebook
  • MySpace
  • Technorati
  • NewsVine
  • Tumblr
  • StumbleUpon

Leave a Reply