You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem regarding the usage of src/config.ts and PolykeyAgent.ts. The PK_INGRESS_PORT has to be propagated from env variables to the ReverseProxy.createReverseProxy().
However we noticed during the integration of js-async-init, some things weren't done exactly the way it's supposed to be.
In PolykeyAgent, the structure at the end of createPolykeyAgent should be:
The reason to have an asynchronous createX static constructor is to call the start and ensure that constructed instances are started already. If this wasn't intended, then you only needed the StartStop decorator, not the CreateDestroyStartStop decorator.
The fact that PolykeyAgent wasn't done this way, may mean that other classes that are using the CreateDestroyStartStop pattern are also doing it incorrectly.
Now because the createX static methods are meant to call the asynchronous start, this means start parameters/options must be available in the createX static methods. The ReverseProxy has these parameters:
Note the difference between constructor parameters and start parameters. In the recent work on EFS and js-db, it's better to put parameters into the constructor if it is expected that they will stick around as class properties. Only if the parameters are temporary to the asynchronous start, then you should have them in the start method. This means there are some changes required to the PK domains that haven't yet been done.
In ReverseProxy, there are some cases where start does require parameters, because for example ingressPort can be set to 0, and then it has be resolved subsequently to the actual port, and that's why it is in the start method.
Tasks
Review all uses of CreateDestroyStartStop decorator and ensure that their createX functions are calling start
Move any parameter that is meant to be stored as a class property and doesn't require asynchronous operations on them to the constructor instead of start.
Propagate all remaining start parameters to the createX functions so that when calling create you can parameterise the asynchronous creation.
order of parameters: required constructor, required start, optional constructor, optional start
Change to using CDSS when there is underlying state, destroy should destroy the underlying state, while stop doesn't, remember destroy is propagated from the top level
CreateDestroyStartStop should be using 3 exceptions: ErrorXRunning, ErrorXDestroyed, and ErrorXRunning, refer to the parameter name of the decorators to see what to use
Specify default values in parameters inside the function signature like { x = false }: { x: boolean; }, then for encapsulated dependencies use x = x ?? await X.createX() style. This should reduce the line noise.
For CDSS pattern, make sure default values are on the createX but not the constructor. In some cases we will put defaults also on the constructor if we expect the class to be also be constructed without the asynchronous create like for `
The info logging should be standardised for createX, destroy, start and stop. Always do this (even if the methods are noops you should still log, this is important to debug the matroska model):
// in the createXlogger.info(`Creating ${this.name}`);logger.info(`Created ${this.name}`);// for the other methodslogger.info(`Starting ${this.constructor.name}`);logger.info(`Started ${this.constructor.name}`);// repeat for stop and destroy
Child loggers should be propagated with class name logger.getChild(Class.name).
Due to recursive dependency for PolykeyAgent instance in agentService, the GRPC related code may need to be SS pattern and not CDSS, check this and investigate. See polykey async-init fixes #281 (comment)
Setting WorkerManager should be dynamic, see src/PolykeyAgent.ts.
The difference between encapsulated dependencies and just external references is whether the dependency is optional. If optional, then it is an encapsulated dependency, if required, then it is an external reference. So you don't manage it's lifecycle, which means you don't call create or start.
The createX should be the dual of destroy. So then the domain managed state should be "created" at createX. And destroy should destroy it. However start() should always be called at the end of createX so that way the proper starting operations can be done. However don't use the recursive option for utils.mkdirExistspolykey async-init fixes #281 (comment), but do use recursive option for destroy and also force...
Propagate the start, stop, and destroy into encapsulated dependencies but not required dependencies.
Make sure to test all of this in accordance to the matroska/babushka doll.
update GRPCClient to be inline with the async-init lib updates.
Update relevent getters to use @ready decoration.
Incorporate readiness testing to each one see tests/sessions/Session.ts.
For addressing point 1. #194 (comment)
Problem regarding the usage of
src/config.tsandPolykeyAgent.ts. ThePK_INGRESS_PORThas to be propagated from env variables to theReverseProxy.createReverseProxy().However we noticed during the integration of
js-async-init, some things weren't done exactly the way it's supposed to be.In
PolykeyAgent, the structure at the end ofcreatePolykeyAgentshould be:The reason to have an asynchronous
createXstatic constructor is to call thestartand ensure that constructed instances are started already. If this wasn't intended, then you only needed theStartStopdecorator, not theCreateDestroyStartStopdecorator.The fact that
PolykeyAgentwasn't done this way, may mean that other classes that are using theCreateDestroyStartStoppattern are also doing it incorrectly.Now because the
createXstatic methods are meant to call the asynchronous start, this meansstartparameters/options must be available in thecreateXstatic methods. TheReverseProxyhas these parameters:These need to be replicated to the
createReverseProxy.@tegefaulkes
Note the difference between constructor parameters and
startparameters. In the recent work on EFS andjs-db, it's better to put parameters into the constructor if it is expected that they will stick around as class properties. Only if the parameters are temporary to the asynchronous start, then you should have them in thestartmethod. This means there are some changes required to the PK domains that haven't yet been done.In
ReverseProxy, there are some cases wherestartdoes require parameters, because for exampleingressPortcan be set to0, and then it has be resolved subsequently to the actual port, and that's why it is in thestartmethod.Tasks
CreateDestroyStartStopdecorator and ensure that theircreateXfunctions are callingstartconstructorinstead ofstart.startparameters to thecreateXfunctions so that when calling create you can parameterise the asynchronous creation.destroyshould destroy the underlying state, whilestopdoesn't, rememberdestroyis propagated from the top levelCreateDestroyStartStopshould be using 3 exceptions:ErrorXRunning,ErrorXDestroyed, andErrorXRunning, refer to the parameter name of the decorators to see what to use{ x = false }: { x: boolean; }, then for encapsulated dependencies usex = x ?? await X.createX()style. This should reduce the line noise.createXbut not theconstructor. In some cases we will put defaults also on the constructor if we expect the class to be also be constructed without the asynchronous create like for `createX,destroy,startandstop. Always do this (even if the methods are noops you should still log, this is important to debug the matroska model):logger.getChild(Class.name).PolykeyAgentinstance inagentService, the GRPC related code may need to be SS pattern and not CDSS, check this and investigate. See polykey async-init fixes #281 (comment)WorkerManagershould be dynamic, seesrc/PolykeyAgent.ts.createXshould be the dual ofdestroy. So then the domain managed state should be "created" atcreateX. Anddestroyshould destroy it. Howeverstart()should always be called at the end ofcreateXso that way the proper starting operations can be done. However don't use therecursiveoption forutils.mkdirExistspolykey async-init fixes #281 (comment), but do userecursiveoption fordestroyand alsoforce...start,stop, anddestroyinto encapsulated dependencies but not required dependencies.GRPCClientto be inline with the async-init lib updates.@readydecoration.tests/sessions/Session.ts.