Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ build --host_per_file_copt='external/zlib@-Wno-deprecated-non-prototype'
build --per_file_copt=external/protobuf@-Wno-deprecated-declarations
build --host_per_file_copt=external/protobuf@-Wno-deprecated-declarations

# opt in to capnp deprecation warnings about trying to attach to a refcounted object
build --cxxopt=-DKJ_WARN_REFCOUNTED_ATTACH=1

# TODO(cleanup): Causes warnings with LLVM20, fix and enable again
build --copt=-Wno-nontrivial-memaccess

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/io/trace-stream.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ kj::Maybe<kj::Own<TailStreamWriter>> initializeTailStreamWriter(

auto state = kj::heap<TailStreamWriterState>(kj::mv(streamingTailWorkers), waitUntilTasks);

return kj::refcounted<TailStreamWriter>(
return kj::heap<TailStreamWriter>(
// This lambda is called for every streaming tail event that is reported. We use
// the TailStreamWriterState for this stream to actually handle the event.
// Pay attention to the ownership of state here. The lambda holds a bare
Expand Down
4 changes: 0 additions & 4 deletions src/workerd/io/tracer.c++
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ void PipelineTracer::addTrace(rpc::Trace::Reader reader) {
traces.add(kj::refcounted<Trace>(reader));
}

void PipelineTracer::addTailStreamWriter(kj::Own<tracing::TailStreamWriter>&& writer) {
tailStreamWriters.add(kj::mv(writer));
}

WorkerTracer::WorkerTracer(kj::Rc<PipelineTracer> parentPipeline,
kj::Own<Trace> trace,
PipelineLogLevel pipelineLogLevel,
Expand Down
4 changes: 1 addition & 3 deletions src/workerd/io/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace workerd {
namespace tracing {

// A utility class that receives tracing events and generates/reports TailEvents.
class TailStreamWriter final: public kj::Refcounted {
class TailStreamWriter final {
public:
// If the Reporter returns false, then the writer should transition into a
// closed state.
Expand Down Expand Up @@ -77,8 +77,6 @@ class PipelineTracer: public kj::Refcounted {
// tracer for a subordinate stage to add its collected traces to the parent pipeline.
void addTracesFromChild(kj::ArrayPtr<kj::Own<Trace>> traces);

void addTailStreamWriter(kj::Own<tracing::TailStreamWriter>&& writer);

private:
kj::Vector<kj::Own<Trace>> traces;
kj::Maybe<kj::Own<kj::PromiseFulfiller<kj::Array<kj::Own<Trace>>>>> completeFulfiller;
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/io/worker-entrypoint.c++
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ void WorkerEntrypoint::init(kj::Own<const Worker> worker,
TRACE_EVENT("workerd", "WorkerEntrypoint::init() create new IoContext");
auto actorRef = actor.map([](kj::Own<Worker::Actor>& ptr) -> Worker::Actor& { return *ptr; });

// TODO: Does this refcounted instane always live long enough for ioContextDependency here?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to figure this one out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still an open question?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I stared at the code for a while but couldn't really figure out if we have any lifetime guarantees for the given refcount instance here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I stared at the code for a while but couldn't really develop a good understanding of how long this refcounted IoContext instance lives

return kj::refcounted<IoContext>(threadContext, kj::mv(worker), actorRef, kj::mv(limitEnforcer))
.attach(kj::mv(ioContextDependency));
.attachToThisReference(kj::mv(ioContextDependency));
};

kj::Own<IoContext> context;
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/io/worker.c++
Original file line number Diff line number Diff line change
Expand Up @@ -4086,7 +4086,9 @@ kj::Maybe<uint16_t> Worker::Actor::getHibernationEventType() {

kj::Own<Worker::Actor> Worker::Actor::addRef() {
KJ_IF_SOME(t, tracker) {
return kj::addRef(*this).attach(t.get()->startRequest());
// We can attachToThisReference() here, attached object's lifetime being tied to refcounted
// instance is deliberate.
return kj::addRef(*this).attachToThisReference(t.get()->startRequest());
} else {
return kj::addRef(*this);
}
Expand Down
6 changes: 2 additions & 4 deletions src/workerd/server/server.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2170,9 +2170,6 @@ class Server::WorkerService final: public Service,
actor == kj::none ? ExecutionModel::STATELESS : ExecutionModel::DURABLE_OBJECT;
auto tailStreamWriter = tracing::initializeTailStreamWriter(
streamingTailWorkers.releaseAsArray(), waitUntilTasks);
KJ_IF_SOME(t, tailStreamWriter) {
tracer->addTailStreamWriter(kj::addRef(*t));
}
workerTracer = tracer->makeWorkerTracer(PipelineLogLevel::FULL, executionModel,
kj::none /* scriptId */, kj::none /* stableId */, kj::none /* scriptName */,
kj::none /* scriptVersion */, kj::none /* dispatchNamespace */, nullptr /* scriptTags */,
Expand Down Expand Up @@ -5374,9 +5371,10 @@ kj::Promise<void> Server::startServices(jsg::V8System& v8System,
kj::Own<kj::TlsContext> tls = kj::heap<kj::TlsContext>(kj::mv(options));
auto tlsNetwork = tls->wrapNetwork(*publicNetwork);

// Attaching to refcounted NetworkService is safe since services map is long-lived
auto service = kj::refcounted<NetworkService>(globalContext->headerTable, timer, entropySource,
kj::mv(publicNetwork), kj::mv(tlsNetwork), *tls)
.attach(kj::mv(tls));
.attachToThisReference(kj::mv(tls));

return decltype(services)::Entry{kj::str("internet"_kj), kj::mv(service)};
});
Expand Down
Loading