-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
polykey async-init fixes #281
Comments
Review all uses of CreateDestroyStartStop decorator and ensure that their createX functions are calling start
|
Referencing the diagram from https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/205#note_688426664. list of domains using CreateDestroyStartStop.
|
Checking all relevent domains are calling start when being created.
|
To finish the last two items on the above list I need to convert them to using CreateDestroyStartStop first.
|
It's also PolykeyAgent. It wasn't propagating the start and stop and create and destroy. |
I'm not sure we should have the networking modules start at creation. It means NodeMnanager can't be started before the services, GRPC and proxies are started. but also we're getting a dependency cycle where the clientService depends on PolykeyAgent, Polykeyagent depends on nodeManager and nodemanager depends on the service. Since the networking modules are the most expensive to start up it makes sense that they and by extension PolykeyAgent should start independent of creation. |
@tegefaulkes did you make any WIP commits on the MR: https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213 or was there some unpushed work? |
The reason There may be a way to abstract this the there's circularity here. |
The The See the tests that use |
See this: https://gist.github.com/CMCDragonkai/1dbf5069d9efc11585c27cc774271584. The gist explains the different uses of |
Moving the async-init fixes todo list from the top-level description of #194. Most of these points are already in the task list in this issue, but they're a little more fleshed out here:
|
The current MR https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213 shows how to use Also in our meeting today we realised that we needed to make the networking related domains This can only be achieved by passing For classes using This may apply to |
This will be fixed by https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213 |
From this comment: https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213#note_721681210
It would indicate that a number of places using |
I noticed this call:
In the Now the problem is that usually I've been creating the directories in the But with asynchronous creation, this is important if the directory being created is needed by the dependencies. So the On the otherhand, if each dependency won't really need the state until they themselves are also calling This could mean that side effects don't actually occur until you call I'm trying this out in https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213 |
Note that I removed the |
|
One of the things I had to do is figure out the order of parameters for propagating So now I've done:
Usually there should be no required start parameters... |
@tegefaulkes I've updated the task list regarding the async fixes. |
I changed my mind on this, this should actually be in the |
Fixed up the networking depencency cycle and cleaned up |
Checking
|
Does the networking dependency cycle involve |
Seems like it doesn't. The But it seems like |
Hmm the solution to the async init problem on the abstract class is simply not to have the decorator on the abstract class. Instead decorator on |
Actually to fix the problem of using async init for the Basically the Furthermore, the |
Do we really need readiness testing for all of the domains? since its provided via the asyc-ini library we should assume it works? is there a need to replicate the test for each domain? |
Just a copy of this test that exists in test('session readiness', async () => {
const session = await Session.createSession({
sessionTokenPath: path.join(dataDir, 'token'),
logger
});
await expect(session.destroy()).rejects.toThrow(sessionErrors.ErrorSessionRunning);
// should be a noop
await session.start();
await session.stop();
await session.destroy();
await expect(session.start()).rejects.toThrow(sessionErrors.ErrorSessionDestroyed);
await expect(session.readToken()).rejects.toThrow(sessionErrors.ErrorSessionNotRunning);
await expect(session.writeToken('abc' as SessionToken)).rejects.toThrow(sessionErrors.ErrorSessionNotRunning);
}); That's a CDSS test. CD should be even more simpler. We can create a standard template and copy paste it for each one. It's in order to ensure that the exceptions is being abided by. A quick sanity test for create destroy related work too. |
And no you don't need to test every single method. Just like a one or 2 methods. If there's a class with MANY methods, then just 1 or 2 methods. The simple ones. This test is not attempting to test every single method. Although if there's a limited set of actual "ready" methods, then it can be useful there. See how the expectation is that the method throws an exception. |
@tegefaulkes I made a mistake on the It should be this.name there, example:
|
Fixed the logger defaults. |
Awesome work @tegefaulkes! Last thing to fix is the usage of these:
All of those should be |
Ah I see you've done it. |
This can be closed once https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213 is merged. |
Something was missed, unnecessary For example: db = await DB.createDB({
dbPath,
logger,
crypto: makeCrypto(keyManager),
});
await db.start(); The |
Might need to make an exception regarding |
Removed the unnecessary |
There are some parts of code still checking whether the domains are running or not. This is no longer necessary due to async init creation. We always expect they to be running by the time we are using if (!this.db.running) {
throw new dbErrors.ErrorDBNotRunning();
} Will be removing these as I see these. |
Other places which has this. |
Note that protected methods do not need the |
Should have a documented checklist on all the constraints on using async-init. This should be going to documentation. |
I've noticed all of the Since these are managed internally by the proxies, I'm leaving them out so we can merge for now. However a new issue will be created for this. #293 |
This has been done with the merge of https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213. Left over issues are #293 and larger scale refactoring of nodes in #225. Developer documentation should be written here regarding this usage. |
For addressing point 1. #194 (comment)
Problem regarding the usage of
src/config.ts
andPolykeyAgent.ts
. ThePK_INGRESS_PORT
has 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 ofcreatePolykeyAgent
should be:The reason to have an asynchronous
createX
static constructor is to call thestart
and ensure that constructed instances are started already. If this wasn't intended, then you only needed theStartStop
decorator, not theCreateDestroyStartStop
decorator.The fact that
PolykeyAgent
wasn't done this way, may mean that other classes that are using theCreateDestroyStartStop
pattern are also doing it incorrectly.Now because the
createX
static methods are meant to call the asynchronous start, this meansstart
parameters/options must be available in thecreateX
static methods. TheReverseProxy
has these parameters:These need to be replicated to the
createReverseProxy
.@tegefaulkes
Note the difference between constructor parameters and
start
parameters. 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 thestart
method. This means there are some changes required to the PK domains that haven't yet been done.In
ReverseProxy
, there are some cases wherestart
does require parameters, because for exampleingressPort
can be set to0
, and then it has be resolved subsequently to the actual port, and that's why it is in thestart
method.Tasks
CreateDestroyStartStop
decorator and ensure that theircreateX
functions are callingstart
constructor
instead ofstart
.start
parameters to thecreateX
functions so that when calling create you can parameterise the asynchronous creation.destroy
should destroy the underlying state, whilestop
doesn't, rememberdestroy
is propagated from the top levelCreateDestroyStartStop
should 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.createX
but 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
,start
andstop
. 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)
.PolykeyAgent
instance 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)WorkerManager
should be dynamic, seesrc/PolykeyAgent.ts
.createX
should be the dual ofdestroy
. So then the domain managed state should be "created" atcreateX
. Anddestroy
should destroy it. Howeverstart()
should always be called at the end ofcreateX
so that way the proper starting operations can be done. However don't use therecursive
option forutils.mkdirExists
polykey async-init fixes #281 (comment), but do userecursive
option fordestroy
and alsoforce
...start
,stop
, anddestroy
into encapsulated dependencies but not required dependencies.GRPCClient
to be inline with the async-init lib updates.@ready
decoration.tests/sessions/Session.ts
.The text was updated successfully, but these errors were encountered: