Issue 63297
Summary `StartSubprocess` gets stuck when opfile limit is large.
Labels new issue
Assignees
Reporter zu1k
    As described in https://github.com/google/sanitizers/issues/1662

https://github.com/llvm/llvm-project/blob/f9d0bf06319203a8cbb47d89c2f39d2c782f3887/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp#L465 

`compiler-rt` uses a crude approach to close file descripters, which causes child processes to get stuck and fill up the CPU when the maximum file descriptor limit is too large. 

It is better to close only the actual open file descriptors rather than traversing the entire potential range. I'm not sure if the following code is generic.

```c
void close_file_descriptors() {
    DIR *dir;
    struct dirent *entry;
 int fd;

    dir = opendir("/proc/self/fd/");
    if (dir == NULL) {
        perror("opendir failed");
        return;
 }

    while ((entry = readdir(dir)) != NULL) {
        fd = atoi(entry->d_name);

        if (fd >= 3) {
 close(fd);
        }
    }

    closedir(dir);
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to