Skip to content

Commit 3e90a06

Browse files
authored
Merge branch 'main' into copilot/fix-94
2 parents 01335cb + d08cd32 commit 3e90a06

3 files changed

Lines changed: 56 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
target: x86_64-unknown-linux-gnu
4040
# - os: windows-latest
4141
# target: x86_64-pc-windows-msvc
42-
- os: blaze/macos-latest
42+
- os: macos-latest
4343
target: aarch64-apple-darwin
4444
runs-on: ${{ matrix.os }}
4545
steps:
@@ -59,7 +59,7 @@ jobs:
5959

6060
lint:
6161
name: Lint
62-
runs-on: blaze/macos-latest
62+
runs-on: ubuntu-latest
6363
steps:
6464
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6565

@@ -81,7 +81,7 @@ jobs:
8181

8282
run:
8383
name: Run task
84-
runs-on: blaze/macos-latest
84+
runs-on: ubuntu-latest
8585
steps:
8686
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8787

@@ -118,7 +118,7 @@ jobs:
118118
119119
e2e-test:
120120
name: E2E test
121-
runs-on: blaze/macos-latest
121+
runs-on: ubuntu-latest
122122
steps:
123123
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
124124

@@ -172,3 +172,15 @@ jobs:
172172
echo "✓ Successfully installed dependencies for $repo"
173173
echo ""
174174
done
175+
176+
done:
177+
runs-on: ubuntu-latest
178+
needs:
179+
- test
180+
- lint
181+
- run
182+
- e2e-test
183+
steps:
184+
- run: exit 1
185+
# Thank you, next https://github.com/vercel/next.js/blob/canary/.github/workflows/build_and_test.yml#L379
186+
if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
build-rust:
8-
runs-on: blaze/macos-latest
8+
runs-on: ubuntu-latest
99
strategy:
1010
fail-fast: false
1111
matrix:
@@ -39,7 +39,7 @@ jobs:
3939
- uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5
4040
if: ${{ contains(matrix.target, 'linux') }}
4141
with:
42-
version: 0.14.1
42+
version: 0.15.1
4343

4444
- uses: taiki-e/install-action@ad95d4e02e061d4390c4b66ef5ed56c7fee3d2ce # v2.58.17
4545
if: ${{ contains(matrix.target, 'linux') }}
@@ -94,7 +94,7 @@ jobs:
9494
if-no-files-found: error
9595

9696
Release:
97-
runs-on: blaze/macos-latest
97+
runs-on: ubuntu-latest
9898
needs: build-rust
9999
permissions:
100100
contents: read

crates/fspy_preload_unix/src/client/mod.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{
1818
LazyLock, OnceLock,
1919
atomic::{AtomicU8, AtomicU16, AtomicUsize, Ordering, fence},
2020
},
21-
thread::panicking,
21+
thread::{AccessError, panicking},
2222
time::{Instant, SystemTime},
2323
};
2424

@@ -67,10 +67,13 @@ impl ShmCursor {
6767
}
6868
}
6969

70+
thread_local! {
71+
static SHM_CURSOR: RefCell<Option<ShmCursor>> = RefCell::new(None);
72+
}
73+
7074
pub struct Client {
7175
encoded_payload: EncodedPayload,
7276
shm_id: AtomicUsize,
73-
tls_shm_cursor: ThreadLocal<RefCell<ShmCursor>>,
7477

7578
#[cfg(target_os = "macos")]
7679
posix_spawn_file_actions: OnceLock<libc::posix_spawn_file_actions_t>,
@@ -95,7 +98,6 @@ impl Client {
9598
Self {
9699
shm_id: AtomicUsize::new(0),
97100
encoded_payload,
98-
tls_shm_cursor: ThreadLocal::new(),
99101
#[cfg(target_os = "macos")]
100102
posix_spawn_file_actions: OnceLock::new(),
101103
}
@@ -118,26 +120,35 @@ impl Client {
118120
Ok(ShmCursor { mmap_mut, position: 0 })
119121
}
120122

121-
fn with_shm_buf<R>(
123+
fn with_shm_buf(
122124
&self,
123125
len: usize,
124-
f: impl FnOnce(&mut [u8]) -> anyhow::Result<R>,
125-
) -> anyhow::Result<R> {
126-
let shm_buf =
127-
self.tls_shm_cursor.get_or_try(|| io::Result::Ok(RefCell::new(self.new_shm()?)))?;
126+
f: impl FnOnce(&mut [u8]) -> anyhow::Result<()>,
127+
) -> anyhow::Result<()> {
128+
let result = SHM_CURSOR.try_with(|shm_cursor| {
129+
let mut shm_cursor = shm_cursor.borrow_mut();
130+
let shm_buf = if let Some(some) = shm_cursor.as_mut() {
131+
some
132+
} else {
133+
shm_cursor.insert(self.new_shm()?)
134+
};
128135

129-
let mut shm_buf = shm_buf.borrow_mut();
130-
if let Some(buf) = shm_buf.advance(len) {
131-
f(buf)
132-
} else {
133-
*shm_buf = self.new_shm()?;
134-
let buf = shm_buf.advance(len).with_context(|| {
135-
format!(
136-
"The requested buf ({}) is greater than the shm chunk size ({})",
137-
len, SHM_CHUNK_SIZE
138-
)
139-
})?;
140-
f(buf)
136+
if let Some(buf) = shm_buf.advance(len) {
137+
f(buf)
138+
} else {
139+
*shm_buf = self.new_shm()?;
140+
let buf = shm_buf.advance(len).with_context(|| {
141+
format!(
142+
"The requested buf ({}) is greater than the shm chunk size ({})",
143+
len, SHM_CHUNK_SIZE
144+
)
145+
})?;
146+
f(buf)
147+
}
148+
});
149+
match result {
150+
Ok(ok) => ok,
151+
Err(_) => Ok(()), // Ignore AccessError. TODO(fix): handle AccessError
141152
}
142153
}
143154

@@ -290,11 +301,14 @@ fn init_client() {
290301
let Some(client) = global_client() else {
291302
return;
292303
};
293-
if let Some(shm_cursor) = client.tls_shm_cursor.get() {
294-
// Move the shm cursor to the end so that the next time it's used it will be reset.
304+
let _ = SHM_CURSOR.try_with(|shm_cursor| {
305+
// Move the shm cursor to the end so that the next time it's used a new one will be created.
295306
let mut shm_cursor = shm_cursor.borrow_mut();
307+
let Some(shm_cursor) = shm_cursor.as_mut() else {
308+
return;
309+
};
296310
shm_cursor.position = shm_cursor.mmap_mut.len();
297-
}
311+
});
298312
}
299313
let ret = unsafe { pthread_atfork(None, None, Some(reset_shm_atfork)) };
300314
if ret != 0 {

0 commit comments

Comments
 (0)