Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit b9e9b2b

Browse files
authored
fix: change default task bridge socket file to be in home dir (#605)
1 parent 44817f3 commit b9e9b2b

5 files changed

Lines changed: 103 additions & 23 deletions

File tree

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/worker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ iroh = { workspace = true }
5555
rand_v8 = { workspace = true }
5656
rand_core_v6 = { workspace = true }
5757
dashmap = "6.1.0"
58+
homedir = "0.3"

crates/worker/src/cli/command.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,21 @@ pub async fn execute_command(
423423
.expect("Hardware check should have populated compute_specs")
424424
.storage_path
425425
.clone();
426-
let task_bridge = TaskBridge::new(
426+
let task_bridge = match TaskBridge::new(
427427
None,
428428
metrics_store,
429429
Some(bridge_contracts),
430430
Some(node_config.clone()),
431431
Some(bridge_wallet),
432432
docker_storage_path.clone(),
433433
state.clone(),
434-
);
434+
) {
435+
Ok(bridge) => bridge,
436+
Err(e) => {
437+
error!("❌ Failed to create Task Bridge: {e}");
438+
std::process::exit(1);
439+
}
440+
};
435441

436442
let system_memory = node_config
437443
.compute_specs
@@ -446,7 +452,11 @@ pub async fn execute_command(
446452
cancellation_token.clone(),
447453
gpu,
448454
system_memory,
449-
task_bridge.socket_path.clone(),
455+
task_bridge
456+
.socket_path
457+
.to_str()
458+
.expect("path is valid utf-8 string")
459+
.to_string(),
450460
docker_storage_path,
451461
node_wallet_instance
452462
.wallet

crates/worker/src/docker/taskbridge/bridge.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ use std::{fs, path::Path};
1616
use tokio::io::AsyncReadExt;
1717
use tokio::{io::BufReader, net::UnixListener};
1818

19-
pub const SOCKET_NAME: &str = "metrics.sock";
20-
const DEFAULT_MACOS_SOCKET: &str = "/tmp/com.prime.worker/";
21-
const DEFAULT_LINUX_SOCKET: &str = "/tmp/com.prime.worker/";
19+
const DEFAULT_SOCKET_FILE: &str = "prime-worker/com.prime.worker/metrics.sock";
2220

2321
pub struct TaskBridge {
24-
pub socket_path: String,
22+
pub socket_path: std::path::PathBuf,
2523
pub metrics_store: Arc<MetricsStore>,
2624
pub contracts: Option<Contracts<WalletProvider>>,
2725
pub node_config: Option<Node>,
@@ -47,27 +45,25 @@ impl TaskBridge {
4745
node_wallet: Option<Wallet>,
4846
docker_storage_path: String,
4947
state: Arc<SystemState>,
50-
) -> Arc<Self> {
48+
) -> Result<Arc<Self>> {
5149
let path = match socket_path {
52-
Some(path) => path.to_string(),
50+
Some(path) => std::path::PathBuf::from(path),
5351
None => {
54-
if cfg!(target_os = "macos") {
55-
format!("{DEFAULT_MACOS_SOCKET}{SOCKET_NAME}")
56-
} else {
57-
format!("{DEFAULT_LINUX_SOCKET}{SOCKET_NAME}")
58-
}
52+
let path =
53+
homedir::my_home()?.ok_or(anyhow::anyhow!("failed to get home directory"))?;
54+
path.join(DEFAULT_SOCKET_FILE)
5955
}
6056
};
6157

62-
Arc::new(Self {
58+
Ok(Arc::new(Self {
6359
socket_path: path,
6460
metrics_store,
6561
contracts,
6662
node_config,
6763
node_wallet,
6864
docker_storage_path,
6965
state,
70-
})
66+
}))
7167
}
7268

7369
async fn handle_metric(self: Arc<Self>, input: &MetricInput) -> Result<()> {
@@ -357,7 +353,8 @@ mod tests {
357353
None,
358354
"test_storage_path".to_string(),
359355
state,
360-
);
356+
)
357+
.unwrap();
361358

362359
// Run the bridge in background
363360
let bridge_handle = tokio::spawn(async move { bridge.run().await });
@@ -388,7 +385,8 @@ mod tests {
388385
None,
389386
"test_storage_path".to_string(),
390387
state,
391-
);
388+
)
389+
.unwrap();
392390

393391
// Run bridge in background
394392
let bridge_handle = tokio::spawn(async move { bridge.run().await });
@@ -421,7 +419,8 @@ mod tests {
421419
None,
422420
"test_storage_path".to_string(),
423421
state,
424-
);
422+
)
423+
.unwrap();
425424

426425
let bridge_handle = tokio::spawn(async move { bridge.run().await });
427426

@@ -468,7 +467,8 @@ mod tests {
468467
None,
469468
"test_storage_path".to_string(),
470469
state,
471-
);
470+
)
471+
.unwrap();
472472

473473
let bridge_handle = tokio::spawn(async move { bridge.run().await });
474474

@@ -515,7 +515,8 @@ mod tests {
515515
None,
516516
"test_storage_path".to_string(),
517517
state,
518-
);
518+
)
519+
.unwrap();
519520

520521
let bridge_handle = tokio::spawn(async move { bridge.run().await });
521522

examples/python/taskbridge_basic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import os
55
import threading
66
import platform
7+
from pathlib import Path
78

89
def get_default_socket_path():
910
"""Returns the default socket path based on the operating system."""
10-
return "/tmp/com.prime.worker/metrics.sock" if platform.system() == "Darwin" else "/var/run/com.prime.worker/metrics.sock"
11+
home = Path.home()
12+
return str(home) + "/prime-worker/com.prime.worker/metrics.sock"
1113

1214
def send_message(metrics, task_id=None):
1315
"""Sends a message to the socket."""
@@ -88,4 +90,4 @@ def send_file_info():
8890
for thread in threads:
8991
thread.join()
9092

91-
print("All messages sent!")
93+
print("All messages sent!")

0 commit comments

Comments
 (0)