-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix event sending race condition for pb manager (#1455)
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
- Loading branch information
1 parent
9a89891
commit 0e2642a
Showing
15 changed files
with
160 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
FROM clux/muslrust:1.81.0-stable | ||
# This version is required for GLIBC 2.31 (used by edge servers on Linode) | ||
FROM rust:1.82.0-bullseye AS rust | ||
|
||
WORKDIR /app | ||
COPY Cargo.toml . | ||
COPY src/ src/ | ||
RUN cargo build --release --bin rivet-container-runner | ||
COPY . . | ||
|
||
# Installs shared libs | ||
# | ||
# The FDB version should match `cluster::workflows::server::install::install_scripts::components::fdb::FDB_VERSION` | ||
RUN apt-get update && apt-get install -y libclang-dev protobuf-compiler && \ | ||
curl -Lf -o /lib/libfdb_c.so "https://github.com/apple/foundationdb/releases/download/7.1.60/libfdb_c.x86_64.so" | ||
|
||
RUN \ | ||
--mount=type=cache,target=/root/.cargo/git \ | ||
--mount=type=cache,target=/root/.cargo/registry \ | ||
--mount=type=cache,target=/app/packages/infra/client/target \ | ||
cd packages/infra/client && \ | ||
RUSTFLAGS="--cfg tokio_unstable" cargo build --release --bin rivet-container-runner && \ | ||
mkdir -p /app/dist && \ | ||
mv /app/packages/infra/client/target/release/rivet-container-runner /app/dist/rivet-container-runner | ||
|
||
# Create an empty image and copy binaries into it to minimize the size of the image | ||
FROM scratch | ||
COPY --from=rust /app/dist/ / | ||
|
||
# Allows `docker create` to work even though this fails | ||
CMD [""] |
4 changes: 3 additions & 1 deletion
4
packages/infra/client/container-runner/Dockerfile.dockerignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
* | ||
|
||
!Cargo.lock | ||
!Cargo.toml | ||
!src | ||
!packages | ||
!resources/legacy/proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[package] | ||
name = "pegboard-echo-server" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
version = "0.0.1" | ||
edition = "2021" | ||
authors = ["Rivet Gaming, LLC <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
tiny_http = "0.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
!Cargo.lock | ||
!Cargo.toml | ||
!src | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
packages/infra/client/isolate-v8-runner/Dockerfile.dockerignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
* | ||
|
||
!packages/infra/client/actor-kv | ||
!packages/infra/client/config | ||
!packages/infra/client/isolate-v8-runner/Cargo.toml | ||
!packages/infra/client/isolate-v8-runner/src | ||
!packages/infra/client/isolate-v8-runner/js | ||
|
||
!Cargo.lock | ||
!Cargo.toml | ||
!packages | ||
!resources/legacy/proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::sync::atomic::{AtomicI64, Ordering}; | ||
|
||
use anyhow::*; | ||
use pegboard::protocol; | ||
use tokio::sync::broadcast; | ||
|
||
use crate::Ctx; | ||
|
||
/// Handles sending events in a sequentially consistent order. | ||
pub struct EventSender { | ||
awaiting_event_idx: AtomicI64, | ||
tx: broadcast::Sender<i64>, | ||
} | ||
|
||
impl EventSender { | ||
pub fn new() -> Self { | ||
EventSender { | ||
awaiting_event_idx: AtomicI64::new(0), | ||
tx: broadcast::channel(4).0, | ||
} | ||
} | ||
|
||
pub fn set_idx(&self, idx: i64) { | ||
self.awaiting_event_idx.store(idx, Ordering::SeqCst); | ||
} | ||
|
||
pub async fn send(&self, ctx: &Ctx, event: protocol::Event, idx: i64) -> Result<()> { | ||
// Subscribe before checking the idx | ||
let mut rx = self.tx.subscribe(); | ||
|
||
// Read source of truth | ||
if idx != self.awaiting_event_idx.load(Ordering::SeqCst) { | ||
// Wait for idx from channel | ||
loop { | ||
if rx.recv().await? == idx { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Drop receiver so it does not become a "slow receiver" | ||
drop(rx); | ||
|
||
let wrapped_event = protocol::EventWrapper { | ||
index: idx, | ||
inner: protocol::Raw::new(&event)?, | ||
}; | ||
|
||
ctx.send_packet(protocol::ToServer::Events(vec![wrapped_event])) | ||
.await?; | ||
|
||
// Increment idx only after sending. We don't use `fetch_add` because we need the next value to be | ||
// exactly `idx + 1`. This should always be the case anyway. | ||
self.awaiting_event_idx.store(idx + 1, Ordering::SeqCst); | ||
// An error means there are currently no receivers | ||
let _ = self.tx.send(idx + 1); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ use url::Url; | |
|
||
mod actor; | ||
mod ctx; | ||
mod event_sender; | ||
mod metrics; | ||
mod runner; | ||
mod system_info; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters