Skip to content

Commit

Permalink
fix: update uds
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Jan 24, 2024
1 parent ddd89fd commit 8e47b5d
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 118 deletions.
37 changes: 15 additions & 22 deletions integration/fixtures/utils/pids.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,25 @@ class Pids {

try {
const snapshot = await this.getPsSnapshot();

let overlayPattern;

let nfsPattern;

if (process.platform === 'linux') {
overlayPattern = new RegExp(`overlay.*?${this.nodeModulesDir}`, 'i');
} else if (process.platform === 'darwin') {
overlayPattern = new RegExp(`unionfs.*?${this.nodeModulesDir}`, 'i');
nfsPattern = new RegExp(
console.log(snapshot);
if (process.platform === 'darwin') {
const overlayPattern = new RegExp(`unionfs.*?${this.nodeModulesDir}`, 'i');
const nfsPattern = new RegExp(
`/usr/local/bin/go-nfsv4.*?${this.nodeModulesDir}`, 'i'
);
}
console.log('snapshot', snapshot);

for (const line of snapshot.split('\n')) {
if (overlayPattern.test(line)) {
const fields = line.split(/\s+/);
if (fields.length >= 11) {
const pid = parseInt(fields[1], 10) || 0;
pids.push(pid);
for (const line of snapshot.split('\n')) {
if (overlayPattern.test(line)) {
const fields = line.split(/\s+/);
console.log(fields);
if (fields.length >= 11) {
const pid = parseInt(fields[1], 10) || 0;
pids.push(pid);
}
}
}
if (process.platform === 'darwin') {

if (nfsPattern.test(line)) {
const fields = line.split(/\s+/);
console.log(fields);
if (fields.length >= 11) {
const pid = parseInt(fields[1], 10) || 0;
pids.push(pid);
Expand All @@ -61,4 +54,4 @@ class Pids {
}
}

exports.Pids = Pids;
exports.Pids = Pids;
34 changes: 21 additions & 13 deletions integration/index.2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const assert = require('node:assert');
const coffee = require('coffee');
const semver = require('semver');
const execa = require('execa');
const { setTimeout } = require('node:timers/promises');
const { setTimeout: setTimeoutPromise } = require('node:timers/promises');
const rapid = path.join(__dirname, '../node_modules/.bin/rapid');
const { Pids } = require(path.join(__dirname, './fixtures/utils/pids'));
const {
Expand Down Expand Up @@ -224,20 +224,28 @@ describe('test/index.v2.test.js', () => {
assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2);
await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild')));
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
const nodeModulesDir = path.join(cwd, 'node_modules');

const pidsInstance = new Pids('esbuild/node_modules');
let pids = await pidsInstance.getPids();
assert(pids.length > 0);
for (const pid of pids) {
await execa.command(`kill -9 ${pid}`);
if (process.platform === 'linux') {
await execa.command(`umount -f ${nodeModulesDir}`);

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
await setTimeoutPromise(10000);
}
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, 10000);
});
pids = await pidsInstance.getPids();
assert(pids.length > 0);

if (process.platform === 'darwin') {
const pidsInstance = new Pids('esbuild/node_modules');
let pids = await pidsInstance.getPids();
assert(pids.length > 0);
await execa.command(`umount -f ${nodeModulesDir}`);

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
pids.sort((a, b) => a - b);
const oldPids = JSON.stringify(pids);
await setTimeoutPromise(10000);
pids = await pidsInstance.getPids();
assert(pids.length > 0);
pids.sort((a, b) => a - b);
const newPids = JSON.stringify(pids);
assert(oldPids !== newPids);
}
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"version": "lerna version --conventional-commits --sign-git-commit --sign-git-tag --no-push --no-private"
},
"devDependencies": {
"lerna": "^7.1.4",
"@eggjs/tsconfig": "^1.0.0",
"@types/mocha": "^8.2.0",
"@types/node": "^18.16.3",
Expand All @@ -38,6 +37,7 @@
"eslint-config-egg": "^12.0.0",
"espower-typescript": "^9.0.2",
"intelli-espower-loader": "^1.0.1",
"lerna": "^7.1.4",
"mm": "^2.2.0",
"mocha": "^8.2.1",
"nyc": "^15.1.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/lib/deamon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const deamonDir = path.join(baseRapidModeDir(), 'project');

const metadataDir = path.join(deamonDir, 'metadata');

// const deamonSocketPath = path.join(deamonDir, 'socket_path');
const deamonSocketPath = path.join(deamonDir, 'socket_path');

const rapidDeamon = rsBindingPath
? path.join(rsBindingPath, 'rapid_deamon')
Expand All @@ -38,7 +38,7 @@ const checkDeamonAlive = async () => {
try {
const result = await urllib.request(`${aliveUrl}`, {
method: 'GET',
// socketPath: deamonSocketPath,
socketPath: deamonSocketPath,
timeout: 1000,
});
return result.status === 200;
Expand Down Expand Up @@ -73,7 +73,7 @@ const delProject = async projectName => {
data: { projectPath: config.projectPath },
dataType: 'json',
contentType: 'json',
// socketPath: deamonSocketPath,
socketPath: deamonSocketPath,
});
return result.status === 200 && result.data?.code === 0;
} catch (error) {
Expand All @@ -91,7 +91,7 @@ const addProject = async config => {
data: config,
dataType: 'json',
contentType: 'json',
// socketPath: deamonSocketPath,
socketPath: deamonSocketPath,
});
return result.status === 200 && result.data?.code === 0;
} catch (_) {
Expand Down Expand Up @@ -124,7 +124,7 @@ const killDeamon = async () => {
try {
const result = await urllib.request(`${killUrl}`, {
method: 'GET',
// socketPath: deamonSocketPath,
socketPath: deamonSocketPath,
});
return result.status === 200;
} catch (_) {
Expand Down
6 changes: 4 additions & 2 deletions packages/deamon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ log4rs = "1"
axum = "0.7"
http-body-util = "0.1"
hyper = { version = "0.14", features = ["full"] }
hyper_v1 = { package = "hyper", version = "1", features = ["full"] }
hyperlocal = "0.8"
hyper-util = { version = "0.1.2", features = [
hyper-util = { version = "0.1", features = [
"client",
"client-legacy",
"http1",
"server-auto",
"tokio",
] }
httparse = "1.8"
tower = { version = "0.4", features = ["util"] }

[dev-dependencies]
tower = { version = "0.4", features = ["util"] }
mime = "0.3"
102 changes: 84 additions & 18 deletions packages/deamon/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ pub struct Overlay {
}

impl Overlay {
#[cfg(target_os = "macos")]
pub fn get_pids(&self) -> Result<Vec<u32>> {
let mut pids = vec![];

let snapshot = get_ps_snapshot()?;

#[cfg(target_os = "linux")]
let overlay_pattern = Regex::new(&format!(r#"(?i)overlay.*?{}"#, self.node_modules_dir))?;

#[cfg(target_os = "macos")]
let unionfs = match &self.unionfs {
Some(s) => s,
Expand All @@ -165,7 +163,7 @@ impl Overlay {
))
}
};
#[cfg(target_os = "macos")]

let overlay_pattern =
Regex::new(&format!(r#"(?i){}.*?{}"#, unionfs, self.node_modules_dir))?;

Expand All @@ -183,13 +181,11 @@ impl Overlay {
}
}

#[cfg(target_os = "macos")]
let nfs_pattern = Regex::new(&format!(
r#"(?i)/usr/local/bin/go-nfsv4.*?{}"#,
self.node_modules_dir
))?;

#[cfg(target_os = "macos")]
for line in snapshot.clone().lines() {
if nfs_pattern.is_match(line) {
let fields: Vec<&str> = line.split_whitespace().collect();
Expand All @@ -206,14 +202,18 @@ impl Overlay {

Ok(pids)
}

#[cfg(target_os = "linux")]
pub fn restart(&self) -> Result<Vec<u32>> {
#[cfg(target_os = "linux")]
let unmount_modules_str = format!(r#"umount -f {}"#, self.node_modules_dir);

let _ = start_command(&unmount_modules_str);

let unmount_overlay_str = format!(r#"umount -f {}"#, self.overlay);

let _ = start_command(&unmount_overlay_str);

let tmp_str = format!(r#"mount -t tmpfs tmpfs {}"#, self.overlay);
#[cfg(target_os = "macos")]
let tmp_str = format!(
r#"hdiutil attach -nobrowse -mountpoint {} {}"#,
self.overlay, self.tmp_dmg
);

match start_command(&tmp_str) {
Ok(output) => {
Expand Down Expand Up @@ -241,7 +241,6 @@ impl Overlay {
}
}

#[cfg(target_os = "linux")]
let workdir = match &self.workdir {
Some(s) => s,
None => {
Expand All @@ -251,12 +250,72 @@ impl Overlay {
))
}
};
#[cfg(target_os = "linux")]

let mount_str = format!(
r#"mount -t overlay overlay -o lowerdir={},upperdir={},workdir={} {}"#,
self.mnt, self.upper, workdir, self.node_modules_dir
);
#[cfg(target_os = "macos")]
match start_command(&mount_str) {
Ok(output) => {
if output.status.success() {
info!(
"Overlay restart executed successfully, mountpoint: {:?}",
self.node_modules_dir
);
} else {
return Err(anyhow!(
"Error executing Overlay restart: {:?}, mountpoint: {:?}",
output.status,
self.node_modules_dir
));
}
}
Err(e) => {
return Err(anyhow!(
"Error executing Overlay restart command: {:?}, mountpoint: {:?}",
e,
self.node_modules_dir
));
}
}

let res = vec![];
Ok(res)
}

#[cfg(target_os = "macos")]
pub fn restart(&self) -> Result<Vec<u32>> {
let tmp_str = format!(
r#"hdiutil attach -nobrowse -mountpoint {} {}"#,
self.overlay, self.tmp_dmg
);

match start_command(&tmp_str) {
Ok(output) => {
if output.status.success() {
info!(
"Overlay restart executed successfully, mountpoint: {:?}, tmp_str: {:?}",
self.node_modules_dir, tmp_str
);
} else {
return Err(anyhow!(
"Error executing Overlay restart: {:?}, mountpoint: {:?}, tmp_str: {:?}",
output.status,
self.node_modules_dir,
tmp_str
));
}
}
Err(e) => {
return Err(anyhow!(
"Error executing Overlay restart command: {:?}, mountpoint: {:?}, tmp_str: {:?}",
e,
self.node_modules_dir,
tmp_str
));
}
}

let unionfs = match &self.unionfs {
Some(s) => s,
None => {
Expand All @@ -266,7 +325,7 @@ impl Overlay {
))
}
};
#[cfg(target_os = "macos")]

let mount_str = format!(
r#"{} -o cow,max_files=32768 -o allow_other,use_ino,suid,dev,nobrowse {}=RW:{}=RO {}"#,
unionfs, self.upper, self.mnt, self.node_modules_dir
Expand Down Expand Up @@ -296,7 +355,8 @@ impl Overlay {
}
}

Ok(self.get_pids()?)
let res = self.get_pids()?;
Ok(res)
}
}

Expand Down Expand Up @@ -373,6 +433,7 @@ impl ProjectConfig {
pub fn get_pids(&self) -> Result<Vec<u32>> {
let mut pids = vec![];

#[cfg(target_os = "macos")]
for overlay in self.overlays.iter() {
let ps = overlay.get_pids()?;
pids.extend(ps);
Expand Down Expand Up @@ -472,7 +533,12 @@ impl NydusConfig {
info!("init_daemon executed successfully");
return Ok(());
} else {
error!("Error executing init_daemon: {:?}", output.status);
error!(
"Error executing init_daemon, status: {:?}, stdout: {:?}, stderr: {:?}",
output.status,
std::str::from_utf8(&output.stdout)?,
std::str::from_utf8(&output.stderr)?,
);
}
}
Err(e) => error!("Error executing init_daemon: {:?}", e),
Expand Down
Loading

0 comments on commit 8e47b5d

Please sign in to comment.