Skip to content

Commit

Permalink
fix: Check container response null value (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Oct 14, 2023
1 parent fd989e2 commit 6e31cf3
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/Testcontainers/Containers/DockerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace DotNet.Testcontainers.Containers
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet;
using Docker.DotNet.Models;
using DotNet.Testcontainers.Clients;
using DotNet.Testcontainers.Configurations;
Expand Down Expand Up @@ -472,23 +471,16 @@ protected virtual async Task UnsafeStopAsync(CancellationToken ct = default)
await _client.StopAsync(_container.ID, ct)
.ConfigureAwait(false);

try
{
_container = await _client.Container.ByIdAsync(_container.ID, ct)
.ConfigureAwait(false);
}
catch (DockerApiException)
{
_container = new ContainerInspectResponse();
}
_container = await _client.Container.ByIdAsync(_container.ID, ct)
.ConfigureAwait(false);

Stopped?.Invoke(this, EventArgs.Empty);
}

/// <inheritdoc />
protected override bool Exists()
{
return ContainerHasBeenCreatedStates.HasFlag(State);
return _container != null && ContainerHasBeenCreatedStates.HasFlag(State);
}
}
}

0 comments on commit 6e31cf3

Please sign in to comment.