Skip to content

Commit

Permalink
fix(core): check if signal defined before usage in process.kill
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jan 23, 2025
1 parent d03e687 commit ca21cbf
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/generated/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ It only uses language primitives and immutable objects
### Classes

- [AggregateCreateNodesError](../../devkit/documents/AggregateCreateNodesError)
- [StaleProjectGraphCacheError](../../devkit/documents/StaleProjectGraphCacheError)

### Interfaces

Expand Down
144 changes: 144 additions & 0 deletions docs/generated/devkit/StaleProjectGraphCacheError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Class: StaleProjectGraphCacheError

## Hierarchy

- `Error`

**`StaleProjectGraphCacheError`**

## Table of contents

### Constructors

- [constructor](../../devkit/documents/StaleProjectGraphCacheError#constructor)

### Properties

- [cause](../../devkit/documents/StaleProjectGraphCacheError#cause): unknown
- [message](../../devkit/documents/StaleProjectGraphCacheError#message): string
- [name](../../devkit/documents/StaleProjectGraphCacheError#name): string
- [stack](../../devkit/documents/StaleProjectGraphCacheError#stack): string
- [prepareStackTrace](../../devkit/documents/StaleProjectGraphCacheError#preparestacktrace): Function
- [stackTraceLimit](../../devkit/documents/StaleProjectGraphCacheError#stacktracelimit): number

### Methods

- [captureStackTrace](../../devkit/documents/StaleProjectGraphCacheError#capturestacktrace)

## Constructors

### constructor

**new StaleProjectGraphCacheError**(): [`StaleProjectGraphCacheError`](../../devkit/documents/StaleProjectGraphCacheError)

#### Returns

[`StaleProjectGraphCacheError`](../../devkit/documents/StaleProjectGraphCacheError)

#### Overrides

Error.constructor

## Properties

### cause

`Optional` **cause**: `unknown`

#### Inherited from

Error.cause

---

### message

**message**: `string`

#### Inherited from

Error.message

---

### name

**name**: `string`

#### Inherited from

Error.name

---

### stack

`Optional` **stack**: `string`

#### Inherited from

Error.stack

---

### prepareStackTrace

`Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any`

Optional override for formatting stack traces

**`See`**

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

#### Type declaration

▸ (`err`, `stackTraces`): `any`

##### Parameters

| Name | Type |
| :------------ | :----------- |
| `err` | `Error` |
| `stackTraces` | `CallSite`[] |

##### Returns

`any`

#### Inherited from

Error.prepareStackTrace

---

### stackTraceLimit

`Static` **stackTraceLimit**: `number`

#### Inherited from

Error.stackTraceLimit

## Methods

### captureStackTrace

**captureStackTrace**(`targetObject`, `constructorOpt?`): `void`

Create .stack property on a target object

#### Parameters

| Name | Type |
| :---------------- | :--------- |
| `targetObject` | `object` |
| `constructorOpt?` | `Function` |

#### Returns

`void`

#### Inherited from

Error.captureStackTrace
10 changes: 8 additions & 2 deletions docs/generated/devkit/readCachedProjectGraph.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Function: readCachedProjectGraph

**readCachedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/ProjectGraph) & \{ `computedAt`: `number` ; `errors`: `ProjectGraphErrorTypes`[] }
**readCachedProjectGraph**(`minimumComputedAt?`): [`ProjectGraph`](../../devkit/documents/ProjectGraph)

Synchronously reads the latest cached copy of the workspace's ProjectGraph.

#### Parameters

| Name | Type | Description |
| :------------------- | :------- | :----------------------------------------------------------------------------- |
| `minimumComputedAt?` | `number` | The minimum timestamp that the cached ProjectGraph must have been computed at. |

#### Returns

[`ProjectGraph`](../../devkit/documents/ProjectGraph) & \{ `computedAt`: `number` ; `errors`: `ProjectGraphErrorTypes`[] }
[`ProjectGraph`](../../devkit/documents/ProjectGraph)

**`Throws`**

Expand Down
1 change: 1 addition & 0 deletions docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ It only uses language primitives and immutable objects
### Classes

- [AggregateCreateNodesError](../../devkit/documents/AggregateCreateNodesError)
- [StaleProjectGraphCacheError](../../devkit/documents/StaleProjectGraphCacheError)

### Interfaces

Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/utils/buildable-libs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { output } from 'nx/src/utils/output';
import { dirname, join, relative, extname, resolve } from 'path';
import type * as ts from 'typescript';
import { readTsConfigPaths } from './typescript/ts-config';
import { registerCleanupFn } from 'nx/src/utils/cleanup';

function isBuildable(target: string, node: ProjectGraphProjectNode): boolean {
return (
Expand Down Expand Up @@ -454,7 +455,7 @@ export function createTmpTsConfig(
dependencies,
workspaceRoot
);
process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath));
registerCleanupFn(() => cleanupTmpTsConfigFile(tmpTsConfigPath));

if (useWorkspaceAsBaseUrl) {
parsedTSConfig.compilerOptions ??= {};
Expand Down
6 changes: 5 additions & 1 deletion packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,11 @@ function registerProcessListener() {
registerCleanupFn((signal) => {
childProcesses.forEach((p) => {
if ('connected' in p ? p.connected : p.isAlive) {
p.kill(signal);
if (signal) {
p.kill(signal);
} else {
p.kill();
}
}
});
});
Expand Down
13 changes: 6 additions & 7 deletions packages/nx/src/native/db/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::native::db::connection::NxDbConnection;
use fs4::fs_std::FileExt;
use rusqlite::{Connection, OpenFlags};
use std::fs::{remove_file, File};
use std::path::{Path, PathBuf};
Expand All @@ -12,9 +11,7 @@ pub(super) struct LockFile {

pub(super) fn unlock_file(lock_file: &LockFile) {
if lock_file.path.exists() {
lock_file
.file
.unlock()
fs4::fs_std::FileExt::unlock(&lock_file.file)
.and_then(|_| remove_file(&lock_file.path))
.ok();
}
Expand All @@ -26,8 +23,7 @@ pub(super) fn create_lock_file(db_path: &Path) -> anyhow::Result<LockFile> {
.map_err(|e| anyhow::anyhow!("Unable to create db lock file: {:?}", e))?;

trace!("Getting lock on db lock file");
lock_file
.lock_exclusive()
fs4::fs_std::FileExt::lock_exclusive(&lock_file)
.inspect(|_| trace!("Got lock on db lock file"))
.map_err(|e| anyhow::anyhow!("Unable to lock the db lock file: {:?}", e))?;
Ok(LockFile {
Expand Down Expand Up @@ -77,7 +73,10 @@ pub(super) fn initialize_db(nx_version: String, db_path: &Path) -> anyhow::Resul
Ok(c)
}
Err(reason) => {
trace!("Unable to connect to existing database because: {:?}", reason);
trace!(
"Unable to connect to existing database because: {:?}",
reason
);
trace!("Removing existing incompatible database");
remove_file(db_path)?;

Expand Down
13 changes: 7 additions & 6 deletions packages/nx/src/native/utils/file_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl FileLock {

if file_lock.is_ok() {
// Checking if the file is locked, locks it, so unlock it.
file.unlock()?;
fs4::fs_std::FileExt::unlock(&file)?;
}

Ok(Self {
Expand All @@ -60,9 +60,10 @@ impl FileLock {
}

#[napi]
pub fn unlock(&mut self) {
let _ = self.file.unlock();
pub fn unlock(&mut self) -> Result<()> {
fs4::fs_std::FileExt::unlock(&self.file)?;
self.locked = false;
Ok(())
}

#[napi]
Expand All @@ -72,7 +73,7 @@ impl FileLock {

if file_lock.is_ok() {
// Checking if the file is locked, locks it, so unlock it.
self.file.unlock()?;
fs4::fs_std::FileExt::unlock(&self.file)?;
}

self.locked = file_lock.is_err();
Expand All @@ -90,8 +91,8 @@ impl FileLock {
.write(true)
.create(true)
.open(&lock_file_path)?;
file.lock_shared()?;
file.unlock()?;
fs4::fs_std::FileExt::lock_shared(&file)?;
fs4::fs_std::FileExt::unlock(&file)?;
Ok(())
})
} else {
Expand Down
6 changes: 5 additions & 1 deletion packages/nx/src/tasks-runner/forked-process-task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ export class ForkedProcessTaskRunner {
registerCleanupFn((signal) => {
this.processes.forEach((p) => {
if ('connected' in p ? p.connected : p.isAlive) {
p.kill(signal);
if (signal) {
p.kill(signal);
} else {
p.kill();
}
}
});
});
Expand Down

0 comments on commit ca21cbf

Please sign in to comment.