Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

corrupt archive file (gzip, filesystem) #158

Open
cal101 opened this issue Feb 15, 2021 · 5 comments
Open

corrupt archive file (gzip, filesystem) #158

cal101 opened this issue Feb 15, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@cal101
Copy link

cal101 commented Feb 15, 2021

Describe the bug

I am using the cache plugin to cache an .m2 directory.
Too often the cache gets corrupted.
Assuming that gnu tar should be able to read the archive it looks to me that the created archive is corrupt:

$ tar ztvf m2p2-cache/.m2 | grep xyz
tar: Removing leading `/' from member names
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

To Reproduce

It's not clear when and how this happens.

The configuration to store the cache is

  - name: rebuild-cache
    image: meltwater/drone-cache:dev
    pull: true
    settings:
      backend: "filesystem"
      rebuild: true
      #      debug: true
      cache_key: "m2p2-cache"
      archive_format: "gzip"
      mount:
        - '.m2'
        - '.p2'
    volumes:
      - name: cache
        path: /tmp/cache
    when:
      status:
        - success
        - failure

Expected behavior
Don't create corrupted files.

@hg
Copy link

hg commented Feb 28, 2021

I ran into this a few times. I believe it happens under two specific conditions:

  1. you're using local filesystem storage
  2. multiple builds try to rebuild caches using the same key at the same time

The problem went away after switching the storage method to minio (S3).

@cal101
Copy link
Author

cal101 commented Feb 28, 2021

Both conditions were met by my usage.

Smells like file system backend directly writes to target file instead of
writing to tmp file first and then do an atomic rename.

I fixed it by writing a simple sftp/scp based caching solution instead.

@kakkoyun
Copy link
Contributor

You are totally right, this is something I have overlooked. This should be easily achievable.
Anyone wants to give it a try?

@bdebyl
Copy link
Contributor

bdebyl commented Jul 19, 2022

@cal101 if you are able to share insight on your solution to this problem I would be happy to take a look at implementing this within drone-cache itself to get this resolved!

@bdebyl bdebyl added the bug Something isn't working label Jul 19, 2022
@cal101
Copy link
Author

cal101 commented Nov 21, 2022

@bdebyl Sorry, I didn't saw the notification.

My solution was to not use the cache plugin but write my own solution based on sftp/scp.
My assumption about the bug in the cache plugin is that the new archive file is not written atomically and multiple writers write to the same file.
A typical solution to that is to let each writer write to it's own file, close it and then finally rename the file to the target name which typically is atomic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants