I deployed an AWS Lambda written in C#, and depending on the input I can see in the console the following error message (truncated):
{
"Cause": "{\n \"errorType\": \"IOException\",\n \"errorMessage\":
\"Too many open files : [...]at System.IO.FileSystem.RemoveDirectoryRecursive(String fullPath)
"Error": "IOException",
"ExecutionArn": [...]
I have a (somewhat?¹) good sense of what the error refer to, but I would like to reproduce it at least locally.
When I execute it using AWS .NET Lambda test tool with the exact same input (JSON), I cannot trigger the exception. So I assume that my Windows 10 system is more forgiving about the number of file descriptors than the one on AWS side. So added a call to _setmaxstdio in my Lambda code:
[DllImport("msvcrt.dll")]
public static extern int _setmaxstdio(int newMax);
And then in the main code I call:
int ret = _setmaxstdio(128);
I see a value of 128 being returned in the debugger, but again I cannot reproduce the issue locally using AWS .NET Lambda test tool. I picked 128 so that it is lower than the 1024 value described at:
How would one reproduce the exception locally ?
¹ I suspect that Task.WhenAll is being called on all 1024 threads, which is exactly reaching the limit of 1024 open file descriptors.