Skip to content

Commit

Permalink
Merge pull request #187 from cloudflare/kenton/allow-cancellation
Browse files Browse the repository at this point in the history
Update for Cap'n Proto allowCancellation change.
  • Loading branch information
kentonv authored Dec 2, 2022
2 parents 4e5a058 + 2516db7 commit 3974caf
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 16 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ rules_foreign_cc_dependencies()

http_archive(
name = "capnp-cpp",
sha256 = "7ccdf8eeed127d439bc8a94d5742f87d3e5e305f13c3bbb2797005eb6705bf98",
strip_prefix = "capnproto-capnproto-d0e3946/c++",
sha256 = "f2545a2de980f4de51b28ed305098964e4f4367faa8f70b0178cbc0851c407c4",
strip_prefix = "capnproto-capnproto-3e54cc2/c++",
type = "tgz",
urls = ["https://github.com/capnproto/capnproto/tarball/d0e3946787b635c7196ded373ae867642e0cf5c7"],
urls = ["https://github.com/capnproto/capnproto/tarball/3e54cc22972658393cd430c5d5eac17d1c0a9fb7"],
)

http_archive(
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/api/analytics-engine.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

@0x8fe697b0d6269a23;

$import "/capnp/c++.capnp".namespace("workerd::api");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd::api");
$Cxx.allowCancellation;

# ========================================================================================
# DO NOT MODIFY BELOW THIS COMMENT -- except if copying from the authoritative version.
Expand Down
1 change: 1 addition & 0 deletions src/workerd/api/r2-api.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Cxx = import "/capnp/c++.capnp";
using Json = import "/capnp/compat/json.capnp";

$Cxx.namespace("workerd::api::public_beta");
$Cxx.allowCancellation;

const versionPublicBeta :UInt32 = 1;

Expand Down
4 changes: 3 additions & 1 deletion src/workerd/io/actor-storage.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

@0xb200a391b94343f1;

$import "/capnp/c++.capnp".namespace("workerd::rpc");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd::rpc");
$Cxx.allowCancellation;

interface ActorStorage @0xd7759d7fc87c08e4 {
struct KeyValue {
Expand Down
1 change: 1 addition & 0 deletions src/workerd/io/cdp.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using Cxx = import "/capnp/c++.capnp";
using Json = import "/capnp/compat/json.capnp";

$Cxx.namespace("workerd::cdp");
$Cxx.allowCancellation;

enum LogType {
log @0;
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

@0x8b3d4aaa36221ec8;

$import "/capnp/c++.capnp".namespace("workerd");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd");
$Cxx.allowCancellation;

const supportedCompatibilityDate :Text = "2022-11-08";
# Newest compatibility date that can safely be set using code compiled from this repo. Trying to
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/io/jaeger.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

@0xd25a546ad8e45f46;

$import "/capnp/c++.capnp".namespace("workerd::rpc");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd::rpc");
$Cxx.allowCancellation;

struct JaegerSpan @0x946ed67bd99d1210 {
traceIdHigh @0 :UInt64;
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/io/outcome.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

@0xe27bb9203d5e02a8;

$import "/capnp/c++.capnp".namespace("workerd");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd");
$Cxx.allowCancellation;

# ========================================================================================
# DO NOT MODIFY BELOW THIS COMMENT -- except if copying from the authoritative version.
Expand Down
15 changes: 11 additions & 4 deletions src/workerd/io/worker-interface.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd::rpc");
# We do not use `$Cxx.allowCancellation` because runAlarm() currently depends on blocking
# cancellation.

using import "/capnp/compat/http-over-capnp.capnp".HttpMethod;
using import "/capnp/compat/http-over-capnp.capnp".HttpService;
Expand Down Expand Up @@ -98,16 +100,17 @@ struct AlarmRun @0xfa8ea4e97e23b03d {
interface EventDispatcher @0xf20697475ec1752d {
# Interface used to deliver events to a Worker's global event handlers.

getHttpService @0 () -> (http :HttpService);
getHttpService @0 () -> (http :HttpService) $Cxx.allowCancellation;
# Gets the HTTP interface to this worker (to trigger FetchEvents).

sendTraces @1 (traces :List(Trace));
sendTraces @1 (traces :List(Trace)) $Cxx.allowCancellation;
# Deliver a trace event to a trace worker. This always completes immediately; the trace handler
# runs as a "waitUntil" task.

prewarm @2 (url :Text);
prewarm @2 (url :Text) $Cxx.allowCancellation;

runScheduled @3 (scheduledTime :Int64, cron :Text) -> (result :ScheduledRun);
runScheduled @3 (scheduledTime :Int64, cron :Text) -> (result :ScheduledRun)
$Cxx.allowCancellation;
# Runs a scheduled worker. Returns a ScheduledRun, detailing information about the run such as
# the outcome and whether the run should be retried. This does not complete immediately.

Expand All @@ -117,6 +120,10 @@ interface EventDispatcher @0xf20697475ec1752d {
# scheduledTime is a unix timestamp in milliseconds for when the alarm should be run
# Returns an AlarmRun, detailing information about the run such as
# the outcome and whether the run should be retried. This does not complete immediately.
#
# TODO(cleanup): runAlarm()'s implementation currently relies on *not* allowing cancellation.
# It would be cleaner to handle that inside the implementation so we could mark the entire
# interface (and file) with allowCancellation.

obsolete5 @5();
obsolete6 @6();
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/jsg/rtti.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
@0xb042d6da9e1721ad;
# Runtime information about jsg types and definitions

$import "/capnp/c++.capnp".namespace("workerd::jsg::rtti");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd::jsg::rtti");
$Cxx.allowCancellation;

struct Type {
# A description of the C++ type.
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/server/workerd.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
# afraid to fall back to code for anything the config cannot express, as Workers are very fast
# to execute!

$import "/capnp/c++.capnp".namespace("workerd::server::config");
using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("workerd::server::config");
$Cxx.allowCancellation;

struct Config {
# Top-level configuration for a workerd instance.
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/util/capnp-mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ class MockServer: public kj::Refcounted {
class Server final: public capnp::DynamicCapability::Server {
public:
Server(MockServer& mock)
: capnp::DynamicCapability::Server(mock.schema), mock(kj::addRef(mock)) {}
: capnp::DynamicCapability::Server(mock.schema, {.allowCancellation = true}),
mock(kj::addRef(mock)) {}
~Server() noexcept(false) {
mock->dropped = true;
KJ_IF_MAYBE(w, mock->waiter) {
Expand All @@ -339,7 +340,6 @@ class MockServer: public kj::Refcounted {

kj::Promise<void> call(capnp::InterfaceSchema::Method method,
capnp::CallContext<capnp::DynamicStruct, capnp::DynamicStruct> context) override {
context.allowCancellation();
return kj::newAdaptedPromise<void, ReceivedCall>(*mock, method, kj::mv(context));
}

Expand Down

0 comments on commit 3974caf

Please sign in to comment.