Skip to content

Commit

Permalink
ensure all threads are named, to aid in debugging (#48131)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarneges authored Feb 20, 2025
1 parent 6997a41 commit e42b72b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
11 changes: 7 additions & 4 deletions src/connmgr/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 Fanout, Inc.
* Copyright (C) 2023 Fastly, Inc.
* Copyright (C) 2023-2025 Fastly, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1891,9 +1891,12 @@ impl TestClient {
let (status_s, status_r) = channel::channel(1000);
let (control_s, control_r) = channel::channel(1000);

let thread = thread::spawn(move || {
Self::run(status_s, control_r, zmq_context);
});
let thread = thread::Builder::new()
.name("test-client".to_string())
.spawn(move || {
Self::run(status_s, control_r, zmq_context);
})
.unwrap();

// wait for handler thread to start
assert_eq!(status_r.recv().unwrap(), StatusMessage::Started);
Expand Down
11 changes: 7 additions & 4 deletions src/connmgr/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2020-2023 Fanout, Inc.
* Copyright (C) 2023 Fastly, Inc.
* Copyright (C) 2023-2025 Fastly, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2305,9 +2305,12 @@ impl TestServer {
let (started_s, started_r) = channel::channel(1);
let (stop_s, stop_r) = channel::channel(1);

let thread = thread::spawn(move || {
Self::run(started_s, stop_r, zmq_context);
});
let thread = thread::Builder::new()
.name("test-server".to_string())
.spawn(move || {
Self::run(started_s, stop_r, zmq_context);
})
.unwrap();

// wait for handler thread to start
started_r.recv().unwrap();
Expand Down
42 changes: 24 additions & 18 deletions src/core/qtest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Fastly, Inc.
* Copyright (C) 2023-2025 Fastly, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,15 +55,18 @@ where
let thread = if let Some(f) = output_file {
let f = f.to_owned();

let thread = thread::spawn(move || {
// this will block until the other side opens the file for writing
let f = File::open(&f).unwrap();
let thread = thread::Builder::new()
.name("qtest-log".to_string())
.spawn(move || {
// this will block until the other side opens the file for writing
let f = File::open(&f).unwrap();

// forward the output until EOF or error
if let Err(e) = read_and_print_all(f) {
eprintln!("failed to read log line: {}", e);
}
});
// forward the output until EOF or error
if let Err(e) = read_and_print_all(f) {
eprintln!("failed to read log line: {}", e);
}
})
.unwrap();

Some(thread)
} else {
Expand Down Expand Up @@ -152,15 +155,18 @@ where
let (s, r) = mpsc::channel::<RunQTest>();

// run in the background forever
thread::spawn(move || {
for t in r {
let ret = call_qtest(t.f, output_file.as_deref());

// if receiver is gone, keep going
let _ = t.ret.send(ret);
}
unreachable!();
});
thread::Builder::new()
.name("qtest-run".to_string())
.spawn(move || {
for t in r {
let ret = call_qtest(t.f, output_file.as_deref());

// if receiver is gone, keep going
let _ = t.ret.send(ret);
}
unreachable!();
})
.unwrap();

Mutex::new(s)
});
Expand Down
2 changes: 2 additions & 0 deletions src/proxy/domainmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ class DomainMap::Thread : public QThread

void start()
{
setObjectName("domainmap");

QMutexLocker locker(&m);
QThread::start();
w.wait(&m);
Expand Down

0 comments on commit e42b72b

Please sign in to comment.