Fix Corrupted Chunks: Find & Delete Like A Pro
Hey guys! Ever stumble upon those pesky "Input/output error" messages in your nginx logs while dealing with cached content? It's a real headache, especially when it interrupts your downloads. I'm talking about those corrupted chunks that are ruining your day. Don't worry, in this guide, we'll dive deep into how to swiftly find and obliterate those corrupted chunks from your cache. I’ll also show you how to purge all the chunks associated with a specific Steam game. Let's get started, shall we?
Identifying Corrupted Chunks: The Nginx Log Clues
Let's face it; nobody enjoys troubleshooting, but it's a necessary evil. The good news is that the error messages in your nginx logs provide valuable clues. They're like breadcrumbs leading you to the source of the problem. When you see errors like "sendfile() failed (5: Input/output error)" in your logs, you know something's rotten in the state of your cached content. This error specifically points to a problem with reading the cached file. The client is trying to fetch a chunk, but the server is unable to serve it. This usually happens when the chunk is corrupted or incomplete.
Here’s a typical example of what you might see in your nginx logs:
2025/11/03 16:27:33 [alert] 1961#1961: *13639 sendfile() failed (5: Input/output error), client: 192.168.100.100, server: , request: "GET /depot/990081/chunk/8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427 HTTP/1.1", host: "fastly.cdn.steampipe.steamcontent.com"
In this log entry, the key piece of information is the chunk identifier: 8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427. This unique identifier is your key to finding the corrupted chunk. The log also tells you the depot ID (990081), which might be helpful if you need to investigate further based on the game or content this chunk belongs to.
So, if you spot an error like the one above, the first thing you should do is grab the chunk identifier. Copy that identifier because you'll need it to find the corrupted file within your cache. This is the starting point for your investigation, and from here, we will identify where this corrupt chunk is located.
Now, let's explore how to use the chunk identifier to locate the offending file within your cache, and we will get rid of it!
Hunting Down Corrupted Chunks: Using the find Command
Alright, let's get down to business and locate those corrupted chunks. One of the most effective tools in your arsenal is the find command. It's a powerful utility that lets you search for files based on various criteria. In our case, we'll use it to search for files containing the chunk identifier we extracted from the nginx logs.
Here's the command you mentioned that you're using. It's a great starting point:
find . -type f -exec grep -ril "8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427" {} +
Let's break down what this command does:
find .: This tells the find command to start searching in the current directory (.). You'll likely need to adjust this to the root of your cache directory. For example, if your cache is located at/var/cache/nginx, you should change this tofind /var/cache/nginx. This is important, or you will not find the chunk.-type f: This option tellsfindto look only for files.-exec grep -ril "8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427" {} +: This is where the magic happens. It tellsfindto execute thegrepcommand on each file it finds. Let's break this down further:grep -ril "8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427": This is thegrepcommand, which searches for a specific pattern within files. Let's understand each part of thegrepcommand:-r: This means recursive, sogrepsearches through all subdirectories.-i: This is to make the search case-insensitive. Not always necessary for chunk identifiers, but good practice.-l: This option tellsgrepto print only the name of the file if the pattern is found."8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427": This is the chunk identifier we are searching for. Make sure to replace this with the actual chunk identifier from your nginx logs.
{}: This is a placeholder for the file name thatfindpasses togrep.+: This tellsfindto pass as many file names as possible togrepin a single command, making it more efficient.
When you run this command, find will search your cache directory for any files containing the specified chunk identifier. It will then print the path to those files. This will tell you the exact location of the corrupted chunk. Now that you know where the corrupted chunks are, let's look at how to delete them and other chunks.
Deleting Corrupted Chunks: The rm Command
Once you've identified the corrupted chunks, the next step is to delete them. The rm command is your go-to tool for this task. It's a straightforward command, but it's essential to use it with caution to avoid accidentally deleting important files. To delete a corrupted chunk, you'll use the path you obtained from the find command. It is very simple to do and will quickly clean up your cache.
Here's how you can delete a single corrupted chunk:
rm /path/to/corrupted/chunk/file
Replace /path/to/corrupted/chunk/file with the actual path to the corrupted chunk file that the find command revealed. For example, if the find command outputted /var/cache/nginx/steam/depot/990081/chunk/8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427, then the rm command would be:
rm /var/cache/nginx/steam/depot/990081/chunk/8af5e17a630cc30b8c2e7f4da88dda8e2cfe6427
Important Considerations:
- Double-Check the Path: Before running the 
rmcommand, double-check the path to ensure you're deleting the correct file. One wrong move, and you could accidentally remove other important files. Always make sure you have the right path! - Use with Caution: The 
rmcommand permanently deletes files. There is no recycle bin or undo option. Make sure you know what you are doing before you run it. Be careful, and always verify before deleting. 
After you've deleted the corrupted chunk, the next time a user requests that content, your caching system will fetch it from the origin server and cache the fresh copy. This will resolve the "Input/output error" and allow downloads to proceed smoothly. Deleting the corrupted chunk is a crucial step in maintaining a healthy cache and providing a good user experience.
Bulk Deletion: Removing All Chunks for a Steam Game
Now, let's say you want to delete all chunks associated with a specific Steam game. This might be useful if the game has had an update, or if you suspect there are multiple corrupted chunks. You can adapt the find command to achieve this. Here is how you do it.
First, you need to identify a pattern associated with the game. This pattern could be the game's depot ID or a common directory structure used to store the game's chunks. Let's assume the game's depot ID is 123456. You might find that all the game's chunks are stored in a directory structure like /var/cache/nginx/steam/depot/123456/. This is just an example, so always verify your cache's directory structure.
Here's how you can use the find command to find all the files associated with the game:
find /var/cache/nginx/steam/depot/123456/ -type f
This command will find all files within the directory /var/cache/nginx/steam/depot/123456/. The -type f option ensures that only files are listed and not directories. You can modify the /var/cache/nginx/steam/depot/123456/ part of the command with the correct directory structure for the game you are targeting.
Now, to delete all the chunks, you can pipe the output of the find command to the rm command. The command will search and then remove:
find /var/cache/nginx/steam/depot/123456/ -type f -delete
The -delete option tells find to delete each file it finds. Use this option with extreme caution, as it will permanently delete the files without any confirmation prompts. Always double-check the directory you are targeting before running this command.
Important Considerations for Bulk Deletion:
- Backup (Optional but Recommended): Before bulk deleting any files, it's a good practice to back up your cache, especially if it contains a lot of important data. This will help prevent data loss in case something goes wrong.
 - Verify the Directory: Double-check the directory path to ensure you are targeting the correct game. A typo can lead to deleting the wrong files.
 - Monitor Your Cache: After deleting the chunks, monitor your cache to ensure that the content is being re-cached correctly and that no further errors occur.
 
By following these steps, you can effectively clear out all the chunks associated with a specific Steam game, ensuring that your users get the latest and greatest content.
Optimizing the Process: Speed and Efficiency
Let's talk about optimizing the process to make it quicker and more efficient. Nobody likes wasting time, right? When dealing with potentially large caches, speed becomes a critical factor. Here are some optimization techniques you can use:
- Targeted Searches: Instead of searching the entire cache every time, try to narrow down your search based on the information you have. For example, if you know the depot ID or a specific directory structure associated with the corrupted chunks, use that information in your 
findcommand to limit the search scope. This will dramatically reduce the time it takes to find the files. - Parallelism (Advanced): For more advanced users, you can use tools like 
GNU parallelto run multiplegreporrmcommands in parallel. This can significantly speed up the process, especially on multi-core systems. However, be cautious when using parallelism, as it can consume a lot of system resources. - Regular Cache Maintenance: Implementing a regular cache maintenance schedule is key. This could involve automatically checking for errors in your logs and proactively deleting corrupted chunks. Automation helps prevent problems before they impact users. You could write a script that runs periodically to check your logs and identify any new corrupted chunks. That script can then use the 
findandrmcommands to resolve the issues. Regularly maintaining your cache will keep it healthy, and will improve performance. - Monitoring: Set up monitoring to keep track of your cache's health. You can use tools to monitor your nginx logs for errors and trigger alerts if any issues are detected. Monitoring will allow you to quickly identify problems and resolve them before they impact the user experience. You can monitor the size of your cache, the number of requests being served, and the number of errors being generated. The more you know, the better you can respond.
 
By implementing these optimization techniques, you can ensure that the process of finding and deleting corrupted chunks is as quick and efficient as possible. This will help to keep your caching system healthy and your users happy.
Conclusion: Keeping Your Cache Healthy
And there you have it, guys! We've covered the ins and outs of identifying, finding, and deleting corrupted chunks from your cache. Remember to always double-check the paths and be cautious when using the rm command. Regularly maintaining your cache, monitoring your logs, and implementing the optimization techniques we discussed will help you keep your caching system healthy and your users happy. Keep those downloads flowing smoothly! I hope this guide helps you. Happy caching!