Skip to content

Commit 7bc8269

Browse files
committed
fix(core): check only for watcher connections during inactivity shutdown (#29621)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> We currently second guess our inactivity timer by checking if there are any open connections. However, there's also a strong chance that plugin workers will remain open as long as the daemon is open. This means the daemon stays alive forever and the daemon never shuts down even though it is inactive. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Instead of checking for open connections in general, the daemon server will only check for open file watchers. Most Daemon client requests will restart the server when sending messages so we can safely shut the server down in most cases. The only case where shutting down the daemon would cause a disruption is if a file watcher is registered. In those cases, the daemon will not shutdown due to inactivity. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 32a2ca8)
1 parent dca6048 commit 7bc8269

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/nx/src/daemon/server/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
killSocketOrPath,
1818
} from '../socket-utils';
1919
import {
20+
hasRegisteredFileWatcherSockets,
2021
registeredFileWatcherSockets,
2122
removeRegisteredFileWatcherSocket,
2223
} from './file-watching/file-watcher-sockets';
@@ -311,9 +312,9 @@ export async function handleResult(
311312
}
312313

313314
function handleInactivityTimeout() {
314-
if (numberOfOpenConnections > 0) {
315+
if (hasRegisteredFileWatcherSockets()) {
315316
serverLogger.log(
316-
`There are ${numberOfOpenConnections} open connections. Reset inactivity timer.`
317+
`There are open file watchers. Resetting inactivity timer.`
317318
);
318319
resetInactivityTimeout(handleInactivityTimeout);
319320
} else {

0 commit comments

Comments
 (0)