()
| 109 | return new Promise((resolve, reject) => { |
| 110 | const deadline = Date.now() + posixProcessGroupExitTimeoutMs; |
| 111 | const checkProcessGroup = () => { |
| 112 | try { |
| 113 | process.kill(processGroupId, 0); |
| 114 | } catch (error) { |
| 115 | if (error.code === "ESRCH") { |
| 116 | resolve(); |
| 117 | return; |
| 118 | } |
| 119 | // macOS can report EPERM after the group-wide signal succeeded when no |
| 120 | // remaining group member can be probed by this process. |
| 121 | if (error.code === "EPERM" && process.platform === "darwin") { |
| 122 | resolve(); |
| 123 | return; |
| 124 | } |
| 125 | if (error.code !== "EPERM" || process.platform !== "linux") { |
| 126 | reject( |
| 127 | new Error( |
| 128 | `failed to await POSIX process group ${-processGroupId}: ${error.message}`, |
| 129 | ), |
| 130 | ); |
| 131 | return; |
| 132 | } |
| 133 | // Linux can report EPERM while an unprobeable SUID process remains in |
| 134 | // the group, so continue to the /proc live-member check below. |
| 135 | } |
| 136 | try { |
| 137 | if ( |
| 138 | process.platform === "linux" && |
| 139 | !linuxProcessGroupHasLiveMembers(-processGroupId) |
| 140 | ) { |
| 141 | resolve(); |
| 142 | return; |
| 143 | } |
| 144 | } catch (error) { |
| 145 | reject(error); |
| 146 | return; |
| 147 | } |
| 148 | if (Date.now() >= deadline) { |
| 149 | reject( |
| 150 | new PosixProcessGroupExitTimeout( |
| 151 | `timed out awaiting POSIX process group ${-processGroupId}`, |
| 152 | ), |
| 153 | ); |
| 154 | return; |
| 155 | } |
| 156 | setTimeout(checkProcessGroup, 25); |
| 157 | }; |
| 158 | |
| 159 | checkProcessGroup(); |
| 160 | }); |
no test coverage detected