Details
-
Bug
-
Status: Closed
-
Blocker
-
Resolution: Duplicate
-
DataMapper 1.6.1
-
None
-
Tested and confirmed on Windows 2000 and XP with .Net 2.0
Description
If multiple threads call the same procedure at the same instance with debug logging turned on, the logging at the end of ApplyParameterMap will fail. The StringBuilders for the logging are shared across threads and is failing when calling ToString.
I suggest making the StringBuilders local to the function as nothing else is using them anyway. I will include a test patch to make it fail an a patch to fix the issue. For the test to fail, you have to make sure logging is turned on!
Thanks
Mike
Failing lines:
_logger.Debug("Statement Id: [" + statement.Id + "] Parameters: [" + _paramLogList.ToString(0, _paramLogList.Length - 2) + "]");
_logger.Debug("Statement Id: [" + statement.Id + "] Types: [" + _typeLogList.ToString(0, _typeLogList.Length - 2) + "]");
One failing stack trace:
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.Text.StringBuilder.ToString(Int32 startIndex, Int32 length)
at IBatisNet.DataMapper.Commands.DefaultPreparedCommand.ApplyParameterMap(ISqlMapSession session, IDbCommand command, RequestScope request, IStatement statement, Object parameterObject) in C:\Projects\Framework\src\IBatisNet.DataMapper\Commands\DefaultPreparedCommand.cs:line 242
at IBatisNet.DataMapper.Commands.DefaultPreparedCommand.Create(RequestScope request, ISqlMapSession session, IStatement statement, Object parameterObject) in C:\Projects\Framework\src\IBatisNet.DataMapper\Commands\DefaultPreparedCommand.cs:line 84
at IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForObject[T](ISqlMapSession session, Object parameterObject, T resultObject) in C:\Projects\Framework\src\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line 302
at IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForObject[T](ISqlMapSession session, Object parameterObject) in C:\Projects\Framework\src\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line 285
at IBatisNet.DataMapper.SqlMapper.QueryForObject[T](String statementName, Object parameterObject) in C:\Projects\Framework\src\IBatisNet.DataMapper\SqlMapper.cs:line 610