Uploaded image for project: 'iBatis for .NET'
  1. iBatis for .NET
  2. IBATISNET-252

DefaultPreparedCommand.ApplyParameterMap logging errors when multiple threads call same statement at same time.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Duplicate
    • DataMapper 1.6.1
    • DataMapper 1.6.2
    • DataMapper
    • 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

      Attachments

        1. MultiThreadedLoggingFailure.patch
          3 kB
          Michael T. Schall

        Activity

          People

            Unassigned Unassigned
            schallm Michael T. Schall
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: