emscripten-core / emscripten-core/emscripten
Regression: NODERAWFS doesn't seem to be releasing file descriptors
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
```
$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.9 (54675bac246e84ca024c182e477665d21fe2e2f7)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
**Failing command line in full:**
```
emcc -sNODERAWFS -o file_close.js file_close.c
node file_close.js
...lots of output...
Opening file /tmp/test4080
No file descriptors available
```
This is failing because I expect given the code below that I would not run out of file descriptors.
`file_close.c`
```C
#include
#include
#include
#include
static size_t num_digits(unsigned int x) {
size_t digits = 0;
do {
x /=10;
digits++;
} while (x);
return digits;
}
int main() {
FILE *fp;
char base[] = "/tmp/test";
size_t len = strlen(base);
for (unsigned int i = 0; i < 4098; i++) {
size_t newlen = len + num_digits(i);
char* name = (char*)malloc(newlen + 1);
sprintf(name, "%s%u", base, i);
printf("Opening file %s\n", name);
fp = fopen(name, "w");
if (fp == NULL) {
printf("%s\n",strerror(errno));
break;
}
fprintf(fp, "%u", i);
fclose(fp);
free(name);
}
}
```
Note that I close the file after opening it each iteration.
This was found when working on CPython's test suite, but I was able to cut down the repro to repeatedly opening and closing files as in the code above.
**I installed 3.1.8 and this error does not occur.** So I believe this is a regression in 3.1.9.
Contributor guide
Assessment
This issue has not been assessed yet.