@ -15,6 +15,7 @@ namespace Microsoft.Tye.Hosting
{
{
public class DockerRunner : IApplicationProcessor
public class DockerRunner : IApplicationProcessor
{
{
private static readonly TimeSpan DockerStopTimeout = TimeSpan . FromSeconds ( 3 0 ) ;
private readonly ILogger _l ogger ;
private readonly ILogger _l ogger ;
public DockerRunner ( ILogger logger )
public DockerRunner ( ILogger logger )
@ -207,12 +208,17 @@ namespace Microsoft.Tye.Hosting
_l ogger . LogInformation ( "docker logs collection for {ContainerName} complete with exit code {ExitCode}" , replica , result . ExitCode ) ;
_l ogger . LogInformation ( "docker logs collection for {ContainerName} complete with exit code {ExitCode}" , replica , result . ExitCode ) ;
// Docker has a tendency to get stuck so we're going to timeout this shutdown process
// Docker has a tendency to get stuck so we're going to timeout this shutdown process
var timeoutCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 5 ) ) ;
var timeoutCts = new CancellationTokenSource ( DockerStopTimeout ) ;
_l ogger . LogInformation ( "Stopping container {ContainerName} with ID {ContainerId}" , replica , shortContainerId ) ;
_l ogger . LogInformation ( "Stopping container {ContainerName} with ID {ContainerId}" , replica , shortContainerId ) ;
result = await ProcessUtil . RunAsync ( "docker" , $"stop {containerId}" , throwOnError : false , cancellationToken : timeoutCts . Token ) ;
result = await ProcessUtil . RunAsync ( "docker" , $"stop {containerId}" , throwOnError : false , cancellationToken : timeoutCts . Token ) ;
if ( timeoutCts . IsCancellationRequested )
{
_l ogger . LogWarning ( $"Failed to stop container after {DockerStopTimeout.Seconds} seconds, container will most likely be running." , replica , shortContainerId ) ;
}
PrintStdOutAndErr ( service , replica , result ) ;
PrintStdOutAndErr ( service , replica , result ) ;
service . ReplicaEvents . OnNext ( new ReplicaEvent ( ReplicaState . Stopped , status ) ) ;
service . ReplicaEvents . OnNext ( new ReplicaEvent ( ReplicaState . Stopped , status ) ) ;
@ -221,6 +227,11 @@ namespace Microsoft.Tye.Hosting
result = await ProcessUtil . RunAsync ( "docker" , $"rm {containerId}" , throwOnError : false , cancellationToken : timeoutCts . Token ) ;
result = await ProcessUtil . RunAsync ( "docker" , $"rm {containerId}" , throwOnError : false , cancellationToken : timeoutCts . Token ) ;
if ( timeoutCts . IsCancellationRequested )
{
_l ogger . LogWarning ( $"Failed to remove container after {DockerStopTimeout.Seconds} seconds, container will most likely still exist." , replica , shortContainerId ) ;
}
PrintStdOutAndErr ( service , replica , result ) ;
PrintStdOutAndErr ( service , replica , result ) ;
_l ogger . LogInformation ( "Removed container {ContainerName} with ID {ContainerId} exited with {ExitCode}" , replica , shortContainerId , result . ExitCode ) ;
_l ogger . LogInformation ( "Removed container {ContainerName} with ID {ContainerId} exited with {ExitCode}" , replica , shortContainerId , result . ExitCode ) ;