- Newest
- Most votes
- Most comments
This issue with files seemingly vanishing in your Fargate task is likely related to how concurrent file operations interact with the mounted storage in Fargate.
When you're experiencing files that disappear after writing them, this could be due to one of several issues:
-
Uninterruptible Sleep State: When multiple processes are writing to the same filesystem in Fargate, one process might enter an "Uninterruptible sleep" (D) state while writing, which can cause other operations to hang or fail. This is particularly common with network-attached storage like EFS, but can also happen with ephemeral storage under high concurrency.
-
Resource Limitations: Fargate tasks have specific CPU and memory allocations. If your task is running with limited resources, it might struggle with high-volume file operations, especially when creating and accessing 1,000 files in rapid succession.
-
Filesystem Caching Issues: The ephemeral storage in Fargate might not be synchronizing file operations as expected. When you write a file and immediately try to read it, the filesystem might not have completed flushing the data to disk.
To address this issue, you could try:
-
Add Synchronization: Force data flushes periodically using
fsyncor similar mechanisms in your Go code to ensure writes are completed before attempting reads. -
Increase Task Resources: Allocate more CPU and memory to your Fargate task to handle the file operations more efficiently.
-
Reduce Concurrency: Modify your test to create fewer files at once or add delays between operations.
-
Consider EFS with Provisioned Throughput: While you mentioned wanting to avoid EFS due to performance concerns, EFS with Provisioned Throughput mode could provide better performance for your use case if the ephemeral storage continues to be problematic.
-
Check Disk Space: Ensure your task isn't running out of ephemeral storage space during the test.
If you need to continue using ephemeral storage, you might want to implement a retry mechanism for file operations that fail with "no such file or directory" errors, as this could help mitigate the issue while you investigate the root cause.
Sources
Can not download files in Fargate task with mounted EFS volume | AWS re:Post
Troubleshooting mount issues - Amazon Elastic File System
