rheia icon indicating copy to clipboard operation
rheia copied to clipboard

Revise memory management for cancellation callbacks in runtime.Context.

Open lithdew opened this issue 4 years ago • 1 comments

A dirty hack that is being used right now is that runtime.Context stack-allocates a fixed-sized [1024]u8 to serve as the stack for the invocation of async cancellation callbacks.

For all the cancellation callbacks in Rheia so far, the hack works just fine. Though, it would be good to have the stacks of all async cancellation callbacks heap-allocated upon calling runtime.Context.register().

The alternative is to explicitly disallow async cancellation callbacks. The only cancellation callbacks that are async right now are the ones used to cancel pending I/O requests to io_uring. It might be plausible to make I/O cancellation not be async by having all requests to cancel some I/O request R queue R into a linked list which is flushed on every event loop tick iteration.

This issue is blocking the inclusion of 'context hierarchies' into Rheia, which is why all code in Rheia right now avoids creating child contexts that are canceled when a parent context is canceled (by registering a cancelation callback that calls child_context.cancel() to the parent context).

lithdew avatar Aug 22 '21 14:08 lithdew

Fixed in staging branch. Will close once the branch is merged.

The solution that was picked is to explicitly disallow async cancellation callbacks.

lithdew avatar Sep 02 '21 02:09 lithdew