@@ -2339,11 +2339,8 @@ struct MessageQueue {
23392339
23402340class Worker ::Isolate::InspectorChannelImpl final : public v8_inspector::V8Inspector::Channel {
23412341public:
2342- InspectorChannelImpl (kj::Own<const Worker::Isolate> isolateParam,
2343- ExecutorNotifierPair isolateThreadExecutorNotifierPair,
2344- kj::WebSocket& webSocket)
2345- : ioHandler(kj::mv(isolateThreadExecutorNotifierPair), webSocket),
2346- state (kj::heap<State>(this , kj::mv(isolateParam))) {
2342+ InspectorChannelImpl (kj::Own<const Worker::Isolate> isolateParam, kj::WebSocket& webSocket)
2343+ : ioHandler(webSocket), state(kj::heap<State>(this , kj::mv(isolateParam))) {
23472344 ioHandler.connect (*this );
23482345 }
23492346
@@ -2596,12 +2593,11 @@ private:
25962593 // the InspectorChannelImpl and the InspectorClient.
25972594 class WebSocketIoHandler final {
25982595 public:
2599- WebSocketIoHandler (ExecutorNotifierPair isolateThreadExecutorNotifierPair, kj::WebSocket& webSocket)
2600- : isolateThreadExecutor(kj::mv(isolateThreadExecutorNotifierPair.executor)),
2601- incomingQueueNotifier (kj::mv(isolateThreadExecutorNotifierPair.notifier)),
2602- webSocket(webSocket) {
2596+ WebSocketIoHandler (kj::WebSocket& webSocket)
2597+ : webSocket(webSocket) {
26032598 // Assume we are being instantiated on the InspectorService thread, the thread that will do
26042599 // I/O for CDP messages. Messages are delivered to the InspectorChannelImpl on the Isolate thread.
2600+ incomingQueueNotifier = XThreadNotifier::create ();
26052601 outgoingQueueNotifier = XThreadNotifier::create ();
26062602 }
26072603
@@ -2634,20 +2630,7 @@ private:
26342630 // Message pumping promise that should be evaluated on the InspectorService
26352631 // thread.
26362632 kj::Promise<void > messagePump () {
2637- // Although inspector I/O must happen on the InspectorService thread (to make sure breakpoints
2638- // don't block inspector I/O), inspector messages must be actually dispatched on the Isolate
2639- // thread. So, we run the dispatch loop on the Isolate thread.
2640- //
2641- // Note that the above comment is only really accurate in vanilla workerd. In the case of the
2642- // internal Cloudflare Workers runtime, `isolateThreadExecutor` may actually refer to the
2643- // current thread's `kj::Executor`. That's fine; calling `executeAsync()` on the current
2644- // thread's executor just posts the task to the event loop, and everything works as expected.
2645- auto dispatchLoopPromise = isolateThreadExecutor->executeAsync ([this ]() {
2646- return dispatchLoop ();
2647- });
2648- return receiveLoop ()
2649- .exclusiveJoin (kj::mv (dispatchLoopPromise))
2650- .exclusiveJoin (transmitLoop ());
2633+ return receiveLoop ().exclusiveJoin (dispatchLoop ()).exclusiveJoin (transmitLoop ());
26512634 }
26522635
26532636 void send (kj::String message) {
@@ -2688,7 +2671,6 @@ private:
26882671 outgoingQueueNotifier->notify ();
26892672 }
26902673
2691- // Must be called on the InspectorService thread.
26922674 kj::Promise<void > receiveLoop () {
26932675 for (;;) {
26942676 auto message = co_await webSocket.receive (MAX_MESSAGE_SIZE);
@@ -2711,7 +2693,6 @@ private:
27112693 }
27122694 }
27132695
2714- // Must be called on the Isolate thread.
27152696 kj::Promise<void > dispatchLoop () {
27162697 for (;;) {
27172698 co_await incomingQueueNotifier->awaitNotification ();
@@ -2721,7 +2702,6 @@ private:
27212702 }
27222703 }
27232704
2724- // Must be called on the InspectorService thread.
27252705 kj::Promise<void > transmitLoop () {
27262706 for (;;) {
27272707 co_await outgoingQueueNotifier->awaitNotification ();
@@ -2748,17 +2728,10 @@ private:
27482728 }
27492729 }
27502730
2751- // We need access to the Isolate thread's kj::Executor to run the inspector dispatch loop. This
2752- // doesn't actually have to be an Own, because the Isolate thread will destroy the Isolate
2753- // before it exits, but it doesn't hurt.
2754- kj::Own<const kj::Executor> isolateThreadExecutor;
2755-
27562731 kj::MutexGuarded<MessageQueue> incomingQueue;
2757- // This XThreadNotifier must be created on the Isolate thread.
27582732 kj::Own<XThreadNotifier> incomingQueueNotifier;
27592733
27602734 kj::MutexGuarded<MessageQueue> outgoingQueue;
2761- // This XThreadNotifier must be created on the InspectorService thread.
27622735 kj::Own<XThreadNotifier> outgoingQueueNotifier;
27632736
27642737 kj::WebSocket& webSocket; // only accessed on the InspectorService thread.
@@ -2908,17 +2881,11 @@ kj::Promise<void> Worker::Isolate::attachInspector(
29082881 headers.set (controlHeaderId, " {\" ewLog\" :{\" status\" :\" ok\" }}" );
29092882 auto webSocket = response.acceptWebSocket (headers);
29102883
2911- // This `attachInspector()` overload is used by the internal Cloudflare Workers runtime, which has
2912- // no concept of a single Isolate thread. Instead, it's okay for all inspector messages to be
2913- // dispatched on the calling thread.
2914- auto executorNotifierPair = ExecutorNotifierPair{};
2915-
2916- return attachInspector (kj::mv (executorNotifierPair), timer, timerOffset, *webSocket)
2884+ return attachInspector (timer, timerOffset, *webSocket)
29172885 .attach (kj::mv (webSocket));
29182886}
29192887
29202888kj::Promise<void > Worker::Isolate::attachInspector (
2921- ExecutorNotifierPair isolateThreadExecutorNotifierPair,
29222889 kj::Timer& timer,
29232890 kj::Duration timerOffset,
29242891 kj::WebSocket& webSocket) const {
@@ -2939,10 +2906,7 @@ kj::Promise<void> Worker::Isolate::attachInspector(
29392906
29402907 lockedSelf.impl ->inspectorClient .setInspectorTimerInfo (timer, timerOffset);
29412908
2942- auto channel = kj::heap<Worker::Isolate::InspectorChannelImpl>(
2943- kj::atomicAddRef (*this ),
2944- kj::mv (isolateThreadExecutorNotifierPair),
2945- webSocket);
2909+ auto channel = kj::heap<Worker::Isolate::InspectorChannelImpl>(kj::atomicAddRef (*this ), webSocket);
29462910 lockedSelf.currentInspectorSession = *channel;
29472911 lockedSelf.impl ->inspectorClient .setChannel (*channel);
29482912
0 commit comments