S h o r t S t o r i e s

// Tales from software development

MySQL Connector/NET hangs on MySqlDataReader.Read()

leave a comment »

I was testing some changes in a data interface that runs as a Windows Service and reads configuration data from a MySQL database. Three different sets of data are read when the service starts and while the first two loaded successfully the third was causing the service to hang.

This was strange because the interface has been running in a live environment for over a year and I hadn’t made any changes in this part of the code.

I executed the stored procedure being called in MySQL QueryBrowser and it returned 42 rows. I restarted the service under the debugger and single-stepped through the calls to MySqlDataReader.Read(). It successfully read the 42 rows and then hung on the next call to Read().

I couldn’t see any reason why the Read() was hanging so, in desperation, I downloaded the latest build of the MySQL Connector/NET, 6.3.6, and replaced the version the service was using, 6.0.3. The good news was that the final call to Read() now failed with a System.Timeout exception rather than hanging forever. The exception message was:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

A timeout on the final Read() didn’t make any sense but it was better than a hang.

I added SQL_BUFFER_RESULT to the query being executed in the stored procedure in the hope that this might solve a buffering problem, if that’s what this was. Now the service failed before the first read with a MySqlException with the following error message:

Subquery returns more than 1 row

This was beginning to make a bit of sense now. I went back to Query Browser and looked at the status area at the bottom of the window and sure enough there was the same error message: Subquery returns more than 1 row

Previously, I’d just seen the 42 rows returned and thought the stored procedure was executing successfully.

So, the problem was that the query returned 42 rows and then failed because of the problem with the subquery. When SQL_BUFFER_RESULT was specified the error occurred before any of the rows were sent to the client.

It seems that there’s a bug here in the Connector/NET. An error that occurs after the first result rows are sent to the client doesn’t necessarily throw an exception. In 6.0.3 the Read() where the error occurs hangs the application while in 6.3.6 it causes a hang that times out and a System.Timeout exception is thrown.

Advertisements

Written by Sea Monkey

June 22, 2011 at 8:00 pm

Posted in Debugging, Development

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: