Bug fix for 6.3.x CServiceManager.cpp

There’s a stupidly obvious, should have been caught at numerous points during pre-release testing, bug in CServiceManager.cpp.

The code below that starts at line 158:

      case RunActionRunAsService :
      {
         if (!StartServices())
         {
            const DWORD lastError = ::GetLastError();

            const _tstring message = messageHeader +
                 _T("Failed to start service.\n\n ") +
                GetLastErrorMessage(lastError);

            MessageBox(message);

            result = 2;
         }
      }

      default :

         throw CException(_T("CServiceInstanceManager::Run()"),
             _T("Unexpected run action:") + ToString(runAction));
   }

Should actually look like this, note the inclusion of the missing break; and the exception source correction:

      case RunActionRunAsService :
      {
         if (!StartServices())
         {
            const DWORD lastError = ::GetLastError();

            const _tstring message = messageHeader +
                 _T("Failed to start service.\n\n ") +
                GetLastErrorMessage(lastError);

            MessageBox(message);

            result = 2;
         }
      }
      break;

      default :

         throw CException(_T("CServiceManager::Run()"),
             _T("Unexpected run action:") + ToString(runAction));
   }

What I find especially annoying about this particular bug is that:

  • this piece of code has pretty good test coverage but we don’t cover this particular case.
  • the black box server tests that run as part of the release process on the build machines run the service examples using the /debug switch to run them as normal executables to avoid the requiring admin rights on the build machines.
  • it’s the most common use case for this particular piece of code which means that the client that reported it to me last night is the only person using 6.3 or later with single instance services and all of the service development that I’ve done recently must have been multiple instance.

The fix above will be released in 6.3.3 which will occur some time next week. Hopefully this is all that it will include, but many clients have upgraded to 6.3.2 from much earlier versions and so there may be a few more issued lurking in there.