You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Execute pod update --no-repo-update --verbose concurrently on build machines.
What did you expect to happen?
I hope the command can be executed normally without accidentally deleting the cocoapods cache.
What happened instead?
Sometimes there may be build failures with the error message Failed to download 'MangoFix': Directory not empty @ dir_s_rmdir - /Users/admin/Library/Caches/CocoaPods/Pods.
At the same time, the entire cocoapods cache directory /Users/chengcong/Library/Caches/CocoaPods/Pods may be deleted. However, all our projects use the same cocoapods version.
From the stack trace, it can be seen that the code that threw the final exception is located at Failed to download. However, this code is a begin, rescue block, so the actual code that caused the exception to occur should be located at download_result = Downloader.download(download_request, target, :can_cache => can_cache).
The sentence Failed to download 'MangoFix': Directory not empty @ dir_s_rmdir - /Users/admin/Library/Caches/CocoaPods/Pods indicates that when executing rmdir to delete a directory, the directory is not empty, and this directory is our cache directory.
# Ensures the cache on disk was created with the same CocoaPods version as# is currently running.## @return [Void]#defensure_matching_versionversion_file=root + 'VERSION'version=version_file.read.stripifversion_file.file?root.rmtreeifversion != Pod::VERSION && root.exist?root.mkpathversion_file.open('w'){ |f| f << Pod::VERSION}end
Here is an operation to delete the cache directory root.rmtree, followed immediately by another line root.mkpath. Therefore, it is suspected that the issue is caused by concurrent operations, because when executing rmtree, another thread may have already created this directory, resulting in the Directory not empty error.
However, my cocoapods version is consistent, and there should not be a situation where rmtree clears cocoapods cache, so it is suspected that the problem is caused by multiple threads reading and writing the VERSION folder.
Problem Verification
To verify my hypothesis, I wrote a demonstration code. By calling the ensure_matching_version method continuously in multiple threads for 10 times, I found that there are indeed cases where the version cannot be read.
I modified the source code of cocoapods and added logs to try to reproduce the scenario on the build machine. As a result, it was found that there is indeed a situation where the version cannot be read, which causes the version comparison to fail and the cache directory to be deleted.
Locking may have an impact on performance. In executing 1000 operations, it took 0.26 seconds without locking, while it took 2.01 seconds with locking.
The text was updated successfully, but these errors were encountered:
We had such issues also with partially unfinished downloads being left in the cache and never getting auto-repaired. Maybe at some point this was caused by OOM issues.
I think just using a lockfile won't make this fully robust. Probably some journaling solution is needed which detects on the next run that the cache is left in a broken state and then it can delete/repair it.
It works very well, thank you so much. When will the CocoaPods author merge this fix? Damn.
很好用,非常感谢。cocoapod作者什么时候能把这个fix合了?册那
它用起來很好,非常感謝。CocoaPods 的作者何時能合併這個修復?該死。
Funciona muy bien, muchas gracias. ¿Cuándo el autor de CocoaPods fusionará esta corrección? Maldición.
Cela fonctionne très bien, merci beaucoup. Quand l'auteur de CocoaPods va-t-il fusionner ce correctif ? Zut.
Es funktioniert sehr gut, vielen Dank. Wann wird der CocoaPods-Autor diesen Fix einfügen? Verdammt.
非常に使いやすい、ありがとうございます。CocoaPodsの作者は、この修正をいつマージしますか?くそ。
Report
What did you do?
pod update --no-repo-update --verbose
concurrently on build machines.What did you expect to happen?
cocoapods
cache.What happened instead?
Failed to download 'MangoFix': Directory not empty @ dir_s_rmdir - /Users/admin/Library/Caches/CocoaPods/Pods
.cocoapods
cache directory/Users/chengcong/Library/Caches/CocoaPods/Pods
may be deleted. However, all our projects use the samecocoapods
version.CocoaPods Environment
Stack
Installation Source
Plugins
Project that demonstrates the issue
Crash stack trace as follows
Problem Analysis
download_result = Downloader.download(download_request, target, :can_cache => can_cache)
.Failed to download 'MangoFix': Directory not empty @ dir_s_rmdir - /Users/admin/Library/Caches/CocoaPods/Pods
indicates that when executingrmdir
to delete a directory, the directory is not empty, and this directory is our cache directory.root.rmtree
, followed immediately by another lineroot.mkpath
. Therefore, it is suspected that the issue is caused by concurrent operations, because when executingrmtree
, another thread may have already created this directory, resulting in theDirectory not empty
error.cocoapods
version is consistent, and there should not be a situation wherermtree
clearscocoapods
cache, so it is suspected that the problem is caused by multiple threads reading and writing theVERSION
folder.Problem Verification
ensure_matching_version
method continuously in multiple threads for 10 times, I found that there are indeed cases where theversion
cannot be read.version
could not be read three times.cocoapods
and added logs to try to reproduce the scenario on the build machine. As a result, it was found that there is indeed a situation where theversion
cannot be read, which causes the version comparison to fail and the cache directory to be deleted.Problem solved
VERSION
file.The text was updated successfully, but these errors were encountered: