Edu encountered a strange problem in the last two weeks, as shown in. The simple description of this bug is the same statement, through MySQL. data, database fetch, the obtained value is unstable, sometimes the correct value can be returned, sometimes the return NULL, initially considered as a bug in our internal ORM framework, however, the executescalar method that directly calls mysqlcommand still reports an error. In addition, this bug can be restored after being restarted. For a period of time, it may be repeated in one day or two days, and I don't know how to start it. Due to this problem, Edu has had many episodes,
This article will give a detailed summary of Edu's experience and lessons in this change. After two years of the project, we will continue to repeat yesterday's story.
Back to this bug. Today I will go back to the mysql. Data source code to find the cause and see several suspicious places.
The executescalar method of mysqlcommand calls the mysqlreader object internally. You can first exclude the errors of the statement itself, because they are true and should indeed be returned and return the correct value most of the time, then the restCodeYou can see
Public override object executescalar ()
{
Lastinsertedid =-1;
Object val = NULL;
Mysqldatareader reader = executereader ();
If (reader = NULL) return NULL;
Try
{
If (reader. Read ())
Val = reader. getvalue (0 );
}
Finally
{
If (reader! = NULL)
{
Reader. Close ();
Lastinsertedid = reader. insertedid;
}
Reader = NULL;
}
Return val;
}
Reader is equal to null, or the result returned by reader is null.
1. If reader is null, failure to build reader may be the cause
When reader returns NULL, what is the possibility?
Code in executereader ()
Catch (mysqlexception ex)
{
// If we caught an exception because of a cancel, then just return null
If (ex. Number = 1317)
{
If (timedout)
Throw new mysqlexception (resources. Timeout );
Return NULL;
}
If (ex. isfatal)
Connection. Close ();
If (ex. Number = 0)
Throw new mysqlexception (resources. fatalerrorduringexecute, ex );
Throw;
}
This catch contains something worth noting,
2. Error Code 1317,
Error: 1317
Sqlstate: 70100
(Er_query_interrupted
)
message: query execution was interrupted
the official explanation is that code execution is interrupted, this is also possible.
To sum up, this holiday is back. I must find out the cause of this bug, and I also find that you are familiar with MySQL. data doesn't understand. Why does the debug output use cmd. executescalar instead of using mysqlreader, you can see the cause of the problem. net, there are already a lot of things can not be seen, if you have read the source code, you must know that the print is in mysqlreader, we are still a low level of debug. I didn't see how brilliant people do it. do not satisfy yourself. You and I are the founders. We have no cool people here.