Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TAR archive has only 20kb when application high load #847

Open
bail16 opened this issue Sep 28, 2023 · 0 comments
Open

TAR archive has only 20kb when application high load #847

bail16 opened this issue Sep 28, 2023 · 0 comments
Labels
bug tar Related to TAR file format

Comments

@bail16
Copy link

bail16 commented Sep 28, 2023

Describe the bug

I have .net framework 4.8 application. I'm building TAR archive from multiple memory streams, everything goes ok when application has low load. After executing performance tests, TAR building crashes. Every package after high load has only 20kb.

Reproduction Code

    public class TarArchiveWriter : IArchiveWriter
    {
        private readonly MemoryStream _memoryStream;
        private readonly TarOutputStream _tarOutputStream;
        private readonly List<IDisposable> _toDispose = new List<IDisposable>();
        public string Extension => "tar";

        public TarArchiveWriter()
        {
            _memoryStream = new MemoryStream();
            _tarOutputStream = new TarOutputStream(_memoryStream, Encoding.UTF8);
        }

        public void Write(string path, string xml)
        {
            var bytes = Encoding.UTF8.GetBytes(xml);
            Write(path, bytes);
        }

        public void Write(string path, byte[] content)
        {
            var entry = TarEntry.CreateTarEntry(path);
            entry.Size = content.Length;
            _tarOutputStream.PutNextEntry(entry);
            var binaryWriter = new BinaryWriter(_tarOutputStream);
            _toDispose.Add(binaryWriter);
            binaryWriter.Write(content);
            binaryWriter.Flush();
            _tarOutputStream.CloseEntry();
        }
   
        public void Write(string path)
        {
            var entry = TarEntry.CreateTarEntry(path);
            _tarOutputStream.PutNextEntry(entry);
        }

        public byte[] GetResult()
        {
            _tarOutputStream.Close();
            return _memoryStream?.ToArray();
        }

        public void Dispose()
        {
            foreach (var disposable in _toDispose)
            {
                disposable?.Dispose();
            }
            _tarOutputStream?.Dispose();
            _memoryStream?.Dispose();        
            _toDispose.Clear();
        }
    }

Steps to reproduce

  • Create .net MVC application on framework 4.8
  • Run high load, performance tests
  • Try to build TAR Archive from memory streams
  • Every package has 20kb

Expected behavior

Package should be build properly

Operating System

Windows

Framework Version

.NET Framework 4.x

Tags

Tar

Additional context

No response

@bail16 bail16 added the bug label Sep 28, 2023
@github-actions github-actions bot added the tar Related to TAR file format label Sep 28, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug tar Related to TAR file format
Projects
None yet
Development

No branches or pull requests

1 participant