Skip to content

Commit

Permalink
Don't implicitly initialize tracing inside test state cleaner
Browse files Browse the repository at this point in the history
When running workers locally, durable object share the same address
space with the main worker, which means they use the same set of global
variables. This means that initializing tracing inside test state
cleaner can cause the worker to crash due to the double initialization
of some components.
  • Loading branch information
mendess committed Aug 29, 2024
1 parent 0558ea5 commit 4de4c38
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions crates/daphne-worker/src/durable/test_state_cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

use std::{cmp::min, ops::ControlFlow};

use crate::{durable::create_span_from_request, initialize_tracing, int_err};
use crate::{durable::create_span_from_request, int_err};
use daphne::messages::TaskId;
use daphne_service_utils::durable_requests::bindings::{self, DurableMethod};
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use tracing::{error, trace, Instrument};
use tracing::Instrument;
use worker::{
async_trait, durable_object, wasm_bindgen, wasm_bindgen_futures, Date, Env, ListOptions,
Method, Request, Response, Result, State, Stub,
async_trait, console_debug, console_error, durable_object, wasm_bindgen, wasm_bindgen_futures,
Date, Env, ListOptions, Method, Request, Response, Result, State, Stub,
};

use super::GcDurableObject;
Expand All @@ -27,7 +27,6 @@ pub struct TestStateCleaner {
#[durable_object]
impl DurableObject for TestStateCleaner {
fn new(state: State, env: Env) -> Self {
initialize_tracing(&env);
Self { state, env }
}

Expand All @@ -49,17 +48,17 @@ impl TestStateCleaner {
bindings::AggregateStore::BINDING => (),
s => {
let message = format!("GarbageCollector: unrecognized binding: {s}");
error!("{}", message);
console_error!("{}", message);
return Err(int_err(message));
}
};

let queued = DurableOrdered::new_roughly_ordered(durable_ref, "object");
queued.put(&self.state).await?;
trace!(
console_debug!(
"registered DO instance for deletion. binding: {binding}, instance: {instance}",
binding = queued.as_ref().binding,
instance = queued.as_ref().id_hex,
"registered DO instance for deletion",
);
Response::from_json(&())
}
Expand Down Expand Up @@ -87,10 +86,10 @@ impl TestStateCleaner {
&(),
)
.await?;
trace!(
console_debug!(
"deleted instance. binding: {binding}. instance: {instance}",
binding = durable_ref.binding,
instance = durable_ref.id_hex,
"deleted instance",
);
}

Expand All @@ -104,7 +103,7 @@ impl TestStateCleaner {
req.method(),
req.path()
);
error!("{}", message);
console_error!("{}", message);
Err(int_err(message))
}
}
Expand Down

0 comments on commit 4de4c38

Please sign in to comment.