Skip to content

The cmf-cli startup very slow or even crash on even commands like --help #668

@pedroapap

Description

@pedroapap

The situation happens on simple commands like cmf --help or any other command.

The main suspicious is linked to the cmf cli on startup making a request to know which is the latest version available.
On system where the network is very limited or even there is none to the internet, this might even crash. Below is an example of one of those crashes:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
     System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.                                                                                                                                                   
          System.TimeoutException: The operation was canceled.                                                                                                                                                                                                                                  
             System.Threading.Tasks.TaskCanceledException: The operation was canceled.                                                                                                                                                                                                          
                  System.IO.IOException: Unable to read data from the transport connection: Operation canceled.                                                                                                                                                                                 
                       System.Net.Sockets.SocketException: Operation canceled                                                                                                                                                                                                                   
                    at void System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)                                                                                                                                      
                    at int System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(short token)                                                                                                                         
                    at async ValueTask<int> System.Net.Security.SslStream.EnsureFullTlsFrameAsync<TIOAdapter>(CancellationToken cancellationToken, int estimatedSize)                                                                                                                           
                    at TResult System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(short token)                                                                                           
                    at async ValueTask<int> System.Net.Security.SslStream.ReadAsyncInternal<TIOAdapter>(Memory<byte> buffer, CancellationToken cancellationToken)                                                                                                                               
                    at TResult System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(short token)                                                                                           
                    at async ValueTask System.Net.Http.HttpConnection.InitialFillAsync(bool async)                                                                                                                                                                                              
                    at async Task<HttpResponseMessage> System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)                                                                                                                    
               at async Task<HttpResponseMessage> System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)                                                                                                                         
               at async ValueTask<HttpResponseMessage> System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, bool async, bool doRequestAuth, CancellationToken cancellationToken)                                                                
               at async ValueTask<HttpResponseMessage> System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, bool async, CancellationToken cancellationToken)                                                                                                                   
               at async Task<HttpResponseMessage> System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, bool disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken             
                  originalCancellationToken)                                                                                                                                                                                                                                                    
       at void System.Net.Http.HttpClient.HandleFailure(Exception e, bool telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)                                                         
       at async Task<HttpResponseMessage> System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, bool disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken                     
          originalCancellationToken)                                                                                                                                                                                                                                                            
       at string Cmf.CLI.Core.Repository.Credentials.PortalRepositoryCredentials.GetPortalBearerToken(string pat) in /home/runner/work/cli/cli/core/Repository/Credentials/PortalRepositoryCredentials.cs:291                                                                                   
       at IEnumerable<ICredential> Cmf.CLI.Core.Repository.Credentials.PortalRepositoryCredentials.GetDerivedCredentials(IList<ICredential> originalCredentials)                                                                                                                                
       at void System.Collections.Generic.List`1.AddRange(IEnumerable<T> collection)                                                                                                                                                                                                            
       at void Cmf.CLI.Core.Services.RepositoryAuthStore.AddDerivedCredentials(CmfAuthFile authFile) in /home/runner/work/cli/cli/core/Services/RepositoryAuthStore.cs:259                                                                                                                      
       at async Task<CmfAuthFile> Cmf.CLI.Core.Services.RepositoryAuthStore.GetOrLoad() in /home/runner/work/cli/cli/core/Services/RepositoryAuthStore.cs:336                                                                                                                                   
       at Core.Objects.CIFSClient..ctor(Uri uri, ISMBClient smbClient) in /home/runner/work/cli/cli/core/Objects/CIFSClient.cs:36                                                                                                                                                               
       at ICIFSClient Cmf.CLI.Core.Objects.ExecutionContext.<>c.<.ctor>b__49_1(Uri uri) in /home/runner/work/cli/cli/core/Objects/ExecutionContext.cs:119                                                                                                                                       
       at List<TResult> System.Linq.Enumerable.WhereSelectListIterator`2.ToList()                                                                                                                                                                                                               
       at Cmf.CLI.Core.Objects.ExecutionContext..ctor(IFileSystem fileSystem) in /home/runner/work/cli/cli/core/Objects/ExecutionContext.cs:117                                                                                                                                                 
       at ExecutionContext Cmf.CLI.Core.Objects.ExecutionContext.Initialize(IFileSystem fileSystem) in /home/runner/work/cli/cli/core/Objects/ExecutionContext.cs:129                                                                                                                           
       at Cmf.CLI.Core.Commands.BaseCommand..ctor(IFileSystem fileSystem) in /home/runner/work/cli/cli/core/Commands/BaseCommand.cs:37                                                                                                                                                          
       at Cmf.CLI.Core.Commands.BaseCommand..ctor() in /home/runner/work/cli/cli/core/Commands/BaseCommand.cs:26                                                                                                                                                                                
       at Cmf.CLI.Commands.BaseCommand..ctor() in /home/runner/work/cli/cli/cmf-cli/Commands/BaseCommand.cs:16                                                                                                                                                                                  
       at Cmf.CLI.Commands.HelpCommand..ctor()                                                                                                                                                                                                                                                  
       at object System.RuntimeType.CreateInstanceDefaultCtor(bool publicOnly, bool wrapExceptions)                                                                                                                                                                                             
  at object System.RuntimeType.CreateInstanceDefaultCtor(bool publicOnly, bool wrapExceptions)                                                                                                                                                                                                  
  at Command Cmf.CLI.Core.Commands.BaseCommand.FindChildCommands(Type cmd, List<Type> commandTypes) in /home/runner/work/cli/cli/core/Commands/BaseCommand.cs:90                                                                                                                                
  at Command Cmf.CLI.Core.Commands.BaseCommand.FindChildCommands(Type cmd, List<Type> commandTypes) in /home/runner/work/cli/cli/core/Commands/BaseCommand.cs:105                                                                                                                               
  at void Cmf.CLI.Core.Commands.BaseCommand.AddChildCommands(Command command) in /home/runner/work/cli/cli/core/Commands/BaseCommand.cs:68                                                                                                                                                      
  at async Task<Tuple<RootCommand, Parser>> Cmf.CLI.Core.StartupModule.Configure(string packageName, string envVarPrefix, string description, string[] args, INPMClient npmClient, Action<IServiceCollection> registerExtraServices) in /home/runner/work/cli/cli/core/StartupModule.cs:85      
  at async Task<int> Cmf.CLI.Program.Main(string[] args) in /home/runner/work/cli/cli/cmf-cli/Program.cs:39 

This has also a lot of impact on CI/CD pipelines that run the cli multiple times. Imagine a simple command takes an additional 20 seconds for this simple request and a pipeline has 15 cli calls, this would be 5 minutes completely wasted on non-productive processing time.

Metadata

Metadata

Labels

bugSomething isn't workingrefactor

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions