realvizu/NsDepCop

Unable to communicate with NsDepCop service. All retries failed on CI Build

seblucas opened this issue · 4 comments

Hi,

First thanks for this tool, it's exactly what we needed to make sure our code is properly decoupled.

Next, unfortunately, I've never managed to make it run with our CI build. I'm using Azure Devops using my own build machine which a Win10 with latest VS2017 (same as my laptop). I always have this error message :

  Utilisation de la compilation partagée avec le compilateur du répertoire : C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn
NsDepCop_Analyze:
  [NsDepCop] Analysing project in folder: C:\agent\_work\10\s\src\Quadra.Affixe2.Application.Bodac.Private
##[error]Exception during NsDepCopTask execution: System.Exception: Unable to communicate with NsDepCop service. All retries failed. ---> System.Runtime.Remoting.RemotingException: Échec de la connexion à un port IPC : Le fichier spécifié est introuvable.
 

Server stack trace: 
   à System.Runtime.Remoting.Channels.Ipc.IpcPort.Connect(String portName, Boolean secure, TokenImpersonationLevel impersonationLevel, Int32 timeout)
   à System.Runtime.Remoting.Channels.Ipc.ConnectionCache.GetConnection(String portName, Boolean secure, TokenImpersonationLevel level, Int32 timeout)
   à System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
   à System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   à Codartis.NsDepCop.Core.Interface.Analysis.Remote.IRemoteDependencyAnalyzer.AnalyzeProject(IAnalyzerConfig config, String[] sourcePaths, String[] referencedAssemblyPaths)
   à Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.InvokeRemoteAnalyzer(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   à Codartis.NsDepCop.Core.Util.RetryHelper.Retry[TResult](Func`1 func, Int32 maxRetryCount, BeforeRetryCallback beforeRetryAction)
   --- Fin de la trace de la pile d'exception interne ---
   à Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.OnAllRetriesFailed(Exception exception)
   à Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.GetIllegalTypeDependencies(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   à Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<PerformAnalysis>d__9.MoveNext()
   à Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<AnalyzeCore>d__8.MoveNext()
   à Codartis.NsDepCop.MsBuildTask.NsDepCopTask.Execute()

I've read all other issues about this config (using 1.9.0), so it should have plenty of time to connect :

<NsDepCopConfig IsEnabled="true" CodeIssueKind="Error" ChildCanDependOnParentImplicitly="true" AnalyzerServiceCallRetryTimeSpans="100,1000,10000,30000">
    <Allowed From="*" To="*" />
    <Disallowed From="Quadra.Affixe2.Application.Bodac.*" To="Quadra.Affixe2.Core.Commun.*" />
    <Disallowed From="Quadra.Affixe2.Application.Bodac.*" To="Quadra.Affixe2.Application.Commun.Private.*" />
</NsDepCopConfig>

It's working perfectly on all developers laptops, the only problem is the CI builds.

Due to the way Azure devops is build, the MSBuild process should run as a system user (NETWORK_SERVICE IIRC), can it cause this problem ?

Thanks in advance.

Sébastien

Hi,

When NsDepCop.ServiceHost starts listening it configures security so that everyone can connect. Here's the relevant code:

private static IpcChannel CreateIpcChannel(string portName)
{
var everyoneAccountName = GetAccountNameForSid(WellKnownSidType.WorldSid);
var properties = new Hashtable
{
["portName"] = portName,
["authorizedGroup"] = everyoneAccountName
};
return new IpcChannel(properties, null, null);
}
private static string GetAccountNameForSid(WellKnownSidType wellKnownSidType)
{
var sid = new SecurityIdentifier(wellKnownSidType, null);
var account = (NTAccount) sid.Translate(typeof(NTAccount));
return account.ToString();
}

Se either this code is broken (maybe it doesn't work well on a localized OS -- I noticed that your Windows speaks French) or the problem is something else.

First we should narrow down the problem a bit.

  • Can you set a different build user temporarly (just to make sure that it causes the problem)?
  • Please check on the build server that NsDepCop.ServiceHost can start and listen. See the details in this chat: #43 (comment)

Sorry for the delay, I'll test that this afternoon and keep you posted.

Se either this code is broken (maybe it doesn't work well on a localized OS -- I noticed that your Windows speaks French) or the problem is something else.

My laptop is also in french and everything is working fine.

I spend all yesterday afternoon looking for an explaination and haven't found a clue. I guess that's a problem on my end. I'll close this. thanks for the help