title: TFS: A service host may only be active on one machine at a time. (type BuildServiceHostOwnershipException)
body: <p>Today we find our tfs bc (build controller) and ba (build agent) does work.<br>
  When bc and ba restart, following error event will be logged in Windows Events.</p>
  
  <blockquote>
    <p>Exception Message: The build service host [build agent name] is currently owned by [build agent name]. A service host may only be active on one machine at a time. (type BuildServiceHostOwnershipException)
    Exception Stack Trace:    at Microsoft.TeamFoundation.Build.Hosting.BuildMachine.StartOperation.End(IAsyncResult result, HttpRouter&amp; router, TfsMessageQueue&amp; messageQueue, List`1&amp; processHosts, MachineLifecycleActivity&amp; traceActivity)
       at Microsoft.TeamFoundation.Build.Hosting.BuildMachine.EndStart(IAsyncResult result)
       at Microsoft.TeamFoundation.Build.Machine.WindowsService.EndStartMachine(IAsyncResult result)</p>
    
    <p>Inner Exception Details:</p>
    
    <p>Exception Message: The build service host [build agent name] is currently
    owned by [build agent name]. A service host may only be active on one machine
    at a time. (type SoapException)SoapException Details:  Exception
    Stack Trace:  </p>
  </blockquote>
  
  <p>Queued build job will be hang up on step: Run On Agent and at last will fail with following error:  </p>
  
  <blockquote>
    <p>Exception Message: TF400324: Team
    Foundation services are not available from the server.Technical
    information (for administrator):  Unable to connect to the remote
    server (type TeamFoundationServiceUnavailableException)Exception Data
    Dictionary:AgentExecution = FalseException Stack Trace:    at
    System.Activities.Statements.Throw.Execute(CodeActivityContext
    context)   at
    System.Activities.CodeActivity.InternalExecute(ActivityInstance
    instance, ActivityExecutor executor, BookmarkManager bookmarkManager) 
    at
    System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
    executor, BookmarkManager bookmarkManager, Location
    resultLocation)Inner Exception Details:Exception Message: Unable to
    connect to the remote server (type WebException)Exception Stack Trace:
    at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult
    asyncResult, TransportContext&amp; context)   at
    System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult
    asyncResult)   at
    Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.CompleteGetRequestStream(IAsyncResult
    result)   at
    Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.EndGetRequestStream(IAsyncResult
    result)Inner Exception Details:Exception Message: 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 [tfs server ip] (type
    SocketException)Exception Stack Trace:    at
    System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)   at
    System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,
    Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address,
    ConnectSocketState state, IAsyncResult asyncResult, Exception&amp;
    exception)  </p>
  </blockquote>
  
  <p>We have tried to re-register build controller and build agent. But doesn't work.</p>