Skip to content

Commit e72bacc

Browse files
fix: Trim tar record padding to avoid broken-pipe failure on Podman (#1684)
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
1 parent fd87bb8 commit e72bacc

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

Testcontainers.slnx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<Project Path="src/Testcontainers.Seq/Testcontainers.Seq.csproj"/>
6767
<Project Path="src/Testcontainers.ServiceBus/Testcontainers.ServiceBus.csproj"/>
6868
<Project Path="src/Testcontainers.Sftp/Testcontainers.Sftp.csproj"/>
69-
<Project Path="src/Testcontainers.Temporalio/Testcontainers.Temporalio.csproj"/>
69+
<Project Path="src/Testcontainers.Temporal/Testcontainers.Temporal.csproj"/>
7070
<Project Path="src/Testcontainers.Toxiproxy/Testcontainers.Toxiproxy.csproj"/>
7171
<Project Path="src/Testcontainers.Typesense/Testcontainers.Typesense.csproj"/>
7272
<Project Path="src/Testcontainers.Weaviate/Testcontainers.Weaviate.csproj"/>
@@ -139,7 +139,7 @@
139139
<Project Path="tests/Testcontainers.Seq.Tests/Testcontainers.Seq.Tests.csproj"/>
140140
<Project Path="tests/Testcontainers.ServiceBus.Tests/Testcontainers.ServiceBus.Tests.csproj"/>
141141
<Project Path="tests/Testcontainers.Sftp.Tests/Testcontainers.Sftp.Tests.csproj"/>
142-
<Project Path="tests/Testcontainers.Temporalio.Tests/Testcontainers.Temporalio.Tests.csproj"/>
142+
<Project Path="tests/Testcontainers.Temporal.Tests/Testcontainers.Temporal.Tests.csproj"/>
143143
<Project Path="tests/Testcontainers.Tests/Testcontainers.Tests.csproj"/>
144144
<Project Path="tests/Testcontainers.Toxiproxy.Tests/Testcontainers.Toxiproxy.Tests.csproj"/>
145145
<Project Path="tests/Testcontainers.Typesense.Tests/Testcontainers.Typesense.Tests.csproj"/>

src/Testcontainers/Containers/TarOutputMemoryStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public TarOutputMemoryStream(string targetDirectoryPath, ILogger logger)
3636
/// </summary>
3737
/// <param name="logger">The logger.</param>
3838
public TarOutputMemoryStream(ILogger logger)
39-
: base(new MemoryStream(), Encoding.Default)
39+
: base(new MemoryStream(), TarArchiveDefaults.TarBlockFactor, Encoding.Default)
4040
{
4141
_logger = logger;
4242
IsStreamOwner = false;

src/Testcontainers/Images/DockerfileArchive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace DotNet.Testcontainers.Images
1010
using System.Threading.Tasks;
1111
using DotNet.Testcontainers.Configurations;
1212
using ICSharpCode.SharpZipLib.Tar;
13-
using Microsoft.Extensions.Logging;
1413
using JetBrains.Annotations;
14+
using Microsoft.Extensions.Logging;
1515

1616
/// <summary>
1717
/// Generates a tar archive with Docker configuration files. The tar archive can be used to build a Docker image.
@@ -192,7 +192,7 @@ public async Task<string> Tar(CancellationToken ct = default)
192192

193193
using (var tarOutputFileStream = new FileStream(dockerfileArchiveFilePath, FileMode.Create, FileAccess.Write))
194194
{
195-
using (var tarOutputStream = new TarOutputStream(tarOutputFileStream, Encoding.Default))
195+
using (var tarOutputStream = new TarOutputStream(tarOutputFileStream, TarArchiveDefaults.TarBlockFactor, Encoding.Default))
196196
{
197197
tarOutputStream.IsStreamOwner = false;
198198

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace DotNet.Testcontainers
2+
{
3+
internal static class TarArchiveDefaults
4+
{
5+
// Keep the record size equal to the block size (512 B) so SharpZipLib does
6+
// not write extra zero padding beyond the two standard EOF blocks. The
7+
// default factor of 20 produces ~8 KB of zeros after EOF, which can trigger
8+
// a race in Podman's archive handler. The tar subprocess exits after the EOF
9+
// blocks while the HTTP sender is still flushing the padding, causing EPIPE
10+
// (HTTP 500 "broken pipe"). See:
11+
// https://github.com/testcontainers/testcontainers-dotnet/issues/1683.
12+
internal const int TarBlockFactor = 1;
13+
}
14+
}

0 commit comments

Comments
 (0)