Specification
We need to support default and client supplied timeouts for the RPCServer handlers.
We need to support some features with this.
- User can provide a timeout when making a client call
- Client calls have default timeouts,
- When a client times out the connection is immediately ended with a timeout code.
- Handlers are provided with a timeout timer as a
TimedCancellable context
- Handlers have a default timeout provided
- Handler timeout can be overridden by the client supplied value but only if it's less than the default.
- When a handler times out is the abort is advisory and then the connection is forced closed after a small delay.
I need to do some prototyping with how I want to implement this. We have two options.
- The RPC system supports timeouts directly.
- RPC system allows timeouts to be supplied via the middleware.
Note that the raw handlers don't support the middleware, It's pretty low level in that respect. So raw handlers wouldn't support timeouts with option 2. Conversely Option 1 means adding a timeout field to the RPC messages since by design the RPC system doesn't interpret or apply constraints to the params.
Given some constraints the first option would mean the timeout feature is always available and enforced. The second option means it's up to the implementation of the middleware and handlers to enforce it. I need to weigh both options after some prototyping. I'm leaning towards option 1, but It may require appending a field to the JSONRPC request message format.
RPCServer changes
- Two parameters have been added to the
RPCServer when creating it. These are defaultTimeout and forceEndDelay. defaultTimeout sets the default amount of time before a handler times out and an abort signal is sent. Since this signal is advisory the forceEndDelay (name subject to change) sets the time between the signal and the streamPair being directly aborted.
- When handling a stream a timeout timer is created sends a timeout abort to the abort controller. When created it is started with a delay of
defaultTimeout. When a handler is selected the timer is reset with the provided timeout for the handler if is is less than the default. If none is set then the timer is just refresh-ed.
- The duplex handler and by extension the other 3 basic handler types will refresh the timeout timer every time a message is sent or received. This is not done by the raw handler for now. A raw handler can directly affect the timeout timer by refreshing or resetting it.
- The handlers have a timeout parameter that can be set when implementing the handler. This will be used as the timeout if it defined and less than the
RPCServer defaultTimeout that was provided.
- The
signal and timer are provided to the handlers as a ctx: ContextTimed. The timer can be refresh-ed or reset(delay) or even cancel(reason). This gives us the freedom to override the timeout behaviour from the handlers if we want that. If that is not desired, we can reduce the functionality by casting it with a more restrictive interface.
Additional context
Tasks
RPCServer handle timeouts and provide them to the handlers
RPCClient takes a timeout value or default and force closes the connection when exceeded.
RPCClient can communicate it's timeout to the RPCServer.
Specification
We need to support default and client supplied timeouts for the RPCServer handlers.
We need to support some features with this.
TimedCancellablecontextI need to do some prototyping with how I want to implement this. We have two options.
Note that the raw handlers don't support the middleware, It's pretty low level in that respect. So raw handlers wouldn't support timeouts with option 2. Conversely Option 1 means adding a timeout field to the RPC messages since by design the RPC system doesn't interpret or apply constraints to the params.
Given some constraints the first option would mean the timeout feature is always available and enforced. The second option means it's up to the implementation of the middleware and handlers to enforce it. I need to weigh both options after some prototyping. I'm leaning towards option 1, but It may require appending a field to the JSONRPC request message format.
RPCServerchangesRPCServerwhen creating it. These aredefaultTimeoutandforceEndDelay.defaultTimeoutsets the default amount of time before a handler times out and an abort signal is sent. Since this signal is advisory theforceEndDelay(name subject to change) sets the time between the signal and the streamPair being directly aborted.defaultTimeout. When a handler is selected the timer isresetwith the provided timeout for the handler if is is less than the default. If none is set then the timer is justrefresh-ed.RPCServerdefaultTimeoutthat was provided.signalandtimerare provided to the handlers as actx: ContextTimed. The timer can berefresh-ed orreset(delay)or evencancel(reason). This gives us the freedom to override the timeout behaviour from the handlers if we want that. If that is not desired, we can reduce the functionality by casting it with a more restrictive interface.Additional context
timedCancellableacross the board to control how long side-effects are allowed to complete #450timedCancellabletoSigchainsuch as the deadline in nodes claim process #243Tasks
RPCServerhandle timeouts and provide them to the handlersRPCClienttakes a timeout value or default and force closes the connection when exceeded.RPCClientcan communicate it's timeout to theRPCServer.