proxb / PoshRSJob

Provides an alternative to PSjobs with greater performance and less overhead to run commands in the background, freeing up the console and allowing throttling on the jobs.
MIT License
541 stars 87 forks source link

Random Issue in accessing Test-NetConnection inside a job #207

Open RaghavendraP opened 4 years ago

RaghavendraP commented 4 years ago

I am using a Test-Netconnection function inside my RsJob. It works well most of the times but every now and then I get an error that says: "The 'Find-NetIPsecRule' command was found in the module 'NetSecurity', but the module could not be loaded. For more information, run 'Import-Module NetSecurity'. I am not sure why this happens only few times but not always if its a problem with module import.

By the way I was not using -ModulesToImport argument of RsJob to pass NetSecurity also I believe its not necessary as it works 95% of the times. But if that is needed, I can give it a try.

Full StackTrace: Exception : System.Management.Automation.CommandNotFoundException: The 'Find-NetIPsecRule' command was found in the module 'NetSecurity', but the module could not be loaded. For more information, run 'Import-Module NetSecurity'. ---> System.Management.Automation.CmdletInvocationException: Collection was modified; enumeration operation may not execute. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.List1.Enumerator.MoveNextRare() at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound) at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name) at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() --- End of inner exception stack trace --- at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke) at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.Invoke[T]() at System.Management.Automation.CommandDiscovery.AutoloadSpecifiedModule(String moduleName, ExecutionContext context, SessionStateEntryVisibility visibility, Exception& exception) --- End of inner exception stack trace --- at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.PSScriptCmdlet.RunClause(Action1 clause, Object dollarUnderbar, Object inputToProcess) at System.Management.Automation.PSScriptCmdlet.DoProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() Message : The 'Find-NetIPsecRule' command was found in the module 'NetSecurity', but the module could not be loaded. For more information, run 'Import-Module NetSecurity'. FQID : CouldNotAutoloadMatchingModule,Test-NetConnection InovcationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at ResolveNetworkSecurityDetails, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\Test-NetConnection.psm1: line 343 at Test-NetConnection, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\Test-NetConnection.psm1: line 615 at XXXXX, : line 261 at , : line 352 TargetObject : Find-NetIPsecRule

MVKozlov commented 4 years ago

I briefly look at the Test-NetConnection code and seems it use Find-NetIPsecRule only when it run under UAC-raised admin Please check it and if it is true, try to preload NetSecurity module because as far as I know nobody test nested module loading

RaghavendraP commented 4 years ago

I've added the NetSecurity to ModulesToImport and will check if the problem is recurring or not. Thanks.

Also, found any reason why it would fail only few times but not always if this is the case? i create almost 100 jobs with a batch size of 25-30 and get this error only in 2-5 jobs and rest went through fine.

MVKozlov commented 4 years ago

I've heard about random module autoloading problem with rsjob but do not meet it so dont explore it

пн, 17 Фев 2020 г., 7:30 Anjana Raghavendra P notifications@github.com:

I've added the NetSecurity to ModulesToImport and will check if the problem is recurring or not. Thanks.

Also, found any reason why it would fail only few times but not always if this is the case? i create almost 100 jobs with a batch size of 25-30 and get this error only in 2-5 jobs and rest went through fine.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/proxb/PoshRSJob/issues/207?email_source=notifications&email_token=AB5Z5J7GWMT5KCRCJ5YOYSTRDIHHBA5CNFSM4KVVTHD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL5AZKQ#issuecomment-586812586, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB5Z5J2GTDIB4O5QMDW56DTRDIHHBANCNFSM4KVVTHDQ .