|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2008-2014 Cisco Systems, Inc. All rights reserved. |
| 2 | + * Copyright (c) 2008-2022 Cisco Systems, Inc. All rights reserved. |
3 | 3 | * Copyright (c) 2009 Sandia National Laboratories. All rights reserved.
|
4 | 4 | * Copyright (c) 2014-2020 Intel, Inc. All rights reserved.
|
5 | 5 | * Copyright (c) 2015 Research Organization for Information Science
|
|
52 | 52 | #include "src/util/pmix_error.h"
|
53 | 53 | #include "src/util/pmix_fd.h"
|
54 | 54 | #include "src/util/pmix_string_copy.h"
|
| 55 | +#include "src/runtime/pmix_rte.h" |
55 | 56 |
|
56 | 57 | /*
|
57 | 58 | * Simple loop over reading from a fd
|
@@ -236,6 +237,22 @@ void pmix_close_open_file_descriptors(int protected_fd)
|
236 | 237 | if (0 > fdmax) {
|
237 | 238 | fdmax = sysconf(_SC_OPEN_MAX);
|
238 | 239 | }
|
| 240 | + // On some OS's (e.g., macOS), the value returned by |
| 241 | + // sysconf(_SC_OPEN_MAX) can be set by the user via "ulimit -n X", |
| 242 | + // where X can be -1 (unlimited) or a positive integer. On macOS |
| 243 | + // in particular, if the user does not set this value, it's |
| 244 | + // unclear how the default value is chosen. Some users have |
| 245 | + // reported seeing arbitrarily large default values (in the |
| 246 | + // billions), resulting in a very large loop over close() that can |
| 247 | + // take minutes/hours to complete, leading the user to think that |
| 248 | + // the app has hung. To avoid this, ensure that we cap the max FD |
| 249 | + // that we'll try to close. This is not a perfect scheme, and |
| 250 | + // there's uncertainty on how the macOS default value works, so we |
| 251 | + // provide the pmix_maxfd MCA var to allow the user to set the max |
| 252 | + // FD value if needed. |
| 253 | + if (-1 == fdmax || pmix_maxfd < fdmax) { |
| 254 | + fdmax = pmix_maxfd; |
| 255 | + } |
239 | 256 | for (int fd = 3; fd < fdmax; fd++) {
|
240 | 257 | if (fd != protected_fd) {
|
241 | 258 | close(fd);
|
|
0 commit comments