-
Notifications
You must be signed in to change notification settings - Fork 0
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
Factor out RPC from Polykey #8
Conversation
c6662b3
to
803581c
Compare
@addievo does this PR fix all the issues mentioned that this PR fixes? Did you separate out all the handlers and other abstract classes? Did you create the excalidraw diagram? |
Also if this is ready for review you must tick of all the tasks mentioned above. And also the final checklist too. |
I thought the diagram wasn't part of the lib rather for pk |
No diagram for js-rpc. |
WIPO Adding matrix packages to package.json WIP Changing dir WIP * Errors added new error type and sig dec for RPCServer RPCServer rewritten without PK dependency. * New utils with isObj and promise methods implemented middleware import fix WIP * Apparently fixing RPCServer.ts fixed all of import issues of RPCClient.ts as well, and client has no PK related imports now, so its fixed? #COPE WIP cping tests from pk to js-rpc experimental Decorators and changing logger version experimental Decorators and changing logger version sleep in utils.ts WIP Test resolve wip wip
7458890
to
379e07a
Compare
Moving on to issues now, overview of issues and complexity
Suggested Approach:
Suggested Approach:
Suggested Approach:
Suggested Approach:
Suggested Approach: |
Hey, You don't want to be resolving the issues directly. Add a "Fixes #5" line to this PR under issues fixed and it will resolve the issue when merged. Seccondly, we want to use the conventional commits style of commit messages. For the above commit
Some Check out conventional commits at https://www.conventionalcommits.org/en/v1.0.0/ |
src/utils/middleware.ts
Outdated
const jsonMessage = messageParser(value.value); | ||
const jsonMessageString = JSON.stringify(jsonMessage); | ||
const jsonMessageWithNewline = jsonMessageString + '\n'; | ||
const jsonMessageObject: T = JSON.parse(jsonMessageWithNewline) as T; | ||
controller.enqueue(jsonMessageObject); | ||
bytesWritten = 0; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what's going on here. Why are you adding a \n
here? Also doing a stringify and parse within the stream here is really expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this done to help solve #1? If so, this would not be correct way of solving this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you answer @tegefaulkes comment above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what's going on here. Why are you adding a
\n
here? Also doing a stringify and parse within the stream here is really expensive.
Serialises the json to string, adds a new line (wherein it makes it human readable per the bare description of the issue) and then deserialises it back to an object. I now see why it might introduce a lot of overhead, lemme see how else I can resolve it. Maybe before it is sent as a stream would be a good place to change it
@tegefaulkes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see that the issue is not clear. It does depend on a bunch of context and previous discussion. I'll expand on it in #1 in a moment.
@addievo squashing was not done. It needs to be done first before you can tick them off. |
#4 requires tests on concurrent timeouts between client and server. Just test what happens, it should all end gracefully. If client times out before server, the server exception is just dropped. |
ToDo:
Previous issues, not necessary for library
|
9ce03bf
to
8cdc054
Compare
@amydevs Can you review if the JSON serialisation/encoding makes sense for the current RPC library. Remember that when we use the RPC system in PK or PKE, we would have different application level exceptions that we would throw. Such exceptions would need to be caught and put under the Furthermore just before the application error is serialised it should be filtered against rules on the underlying data (including all recursive cause). These rules are supposed to be provided by the application in order to prevent any leakage of sensitive data in the exception chain. This was the case before in GRPC, not sure about RPC - confirm that this is in fact tested an demonstrated that it works. Finally with everything that has been exported make sure the index.ts is re-exporting everything fractal-like. |
Client service will have no rules and agent service will have strict rules. |
src/utils/middleware.ts
Outdated
const jsonMessage = messageParser(value.value); | ||
const jsonMessageString = JSON.stringify(jsonMessage); | ||
const jsonMessageWithNewline = jsonMessageString + '\n'; | ||
const jsonMessageObject: T = JSON.parse(jsonMessageWithNewline) as T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is a good idea, JSON.parse(JSON.stringify(...)) is slow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already had a conversation with Aditya, this solution is not correct. It should be on the parser side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
is a keyword in github. If you write fix #1
. Fixes #1
, Fixes: #1
etc etc into a commit message. It will close issue #1 when this commit merges into the main branch. Try to avoid that especially if you're not actually fixing it here.
Same thing is true for Issues and PRs.
Just something to be aware of.
You can prefer to use |
Notes on point 7. MatrixAI/Polykey#551 (comment) should be copied into relevant issues @addievo. Also it wasn't written down there, but timeouts for streams should have 2 timeouts, the default timeout should be the processing of the entire entire stream. And a second optional timeout can be a per-message timeout (per-receved message in particular). Both should default to Since both timers are built into
Not sure if there's already corresponding exceptions for such things. Important Another thing is that when timeout occurs, the |
When @amydevs starts helping here, reserve only a couple hrs for the whitespace problem, it's not entirely critical to the testnet 6 or 7. |
callers and handlers are now refactored * WIP - Newline now works, refers issue #1 node v20 fix feat: handlers implementations are now abstract arrow functions * Fixes #5 [ci skip] * resolves issue 5, makes RPC handlers abstract arrow function properties feat: rename to uppercase [ci skip] fix: handler export fix [ci skip] fix: tsconf from quic [ci skip] fix: dependencies (js quic), events and errors versions, changing to relative imports, jest dev dependency, js-quic tsconfig [ci skip] fix: tests imports, using @ [ci skip] chore: removed sysexits chore: fix default exports for callers and handlers Fixed index for handlers fix: remove @matrixai/id fix: remove @matrixai/id and ix chore : diagram [ci skip] chore : lintfix fix: errors now extend AbstractError [ci skip] fix: undoing fix #1 [ci skip] replacd errorCode with just code, references std error codes from rpc spec feat: events based createDestroy [ci skip] chore: img format fix [ci skip] chore: img in README.md [ci skip] feat: allows the user to pass in a generator function if the user wishes to specify a particular id [ci skip] fix: fixes #7 * Removes graceTimer and related jests chore: idGen name change. idGen parameter in creation and constructor. No longer optional. Only defaulted in one place. wip: added idgen to jests, was missing. [ci skip] wip: reimported ix, since a few tests rely on it. removed, matrixai/id wip: jests for #4 removed, matrixai/id wip: * Implements custom RPC Error codes. * Fixed jest for concurrent timeouts * All errors now have a cause * All errors now use custom error codes. wip: *Client uses ctx timer now wip: *Jests to test concurrency wip: *custom RPC based errors for RPC Client, now all errors have a cause and an error message WIP: * Refactor out sensitiveReplacer WIP: * Refactor out sensitiveReplacer WIP: * Update to latest async init and events * set default timeout to Infinity * jest to check server and client with infinite timeout * fixing jests which broke after changing default timeout to infinity WIP: f1x #4 WIP: f1x #11 f1x: parameterize toError, fromError and replacer wip: tofrom fix: parameterize toError, fromError and replacer fix: Makes concurrent jests non deterministic * Related #4 fix: parameterize replacer toError and fromError, change fromError to return JSONValue, stringify fromError usages * Related #10 fix: Converted global state for fromError to handle it internally. *Related: #10 Reviewed-by: @tegefaulkes [ci skip] chore: Jests for fromError and toError, and using a custom replacer. related: #10 [ci skip]
…ng used) related: #10
a937746
to
39b046a
Compare
# This is the 1st commit message: fix: RPCServer.start is now no longer a factory function fix: fixed RPC tests after async-init change # This is the commit message #2: chore: updated inline documentation according to async-init changes # This is the commit message #3: wip: fixing imports # This is the commit message #4: wip: RPCServer deconstruction # This is the commit message #5: fix: RPCServer start stop order # This is the commit message #6: fix: added back createDestroy back to RPCClient # This is the commit message #7: chore: lintfix # This is the commit message #8: wip: completely removed create destroy from rpcclient # This is the commit message #9: fix: RPCClient tests after async-init changes # This is the commit message #10: wip # This is the commit message #11: fix: idgen is optional in constructor # This is the commit message #12: fix: type import in ./types # This is the commit message #13: chore: test for RPCServer force stopping # This is the commit message #14: fix: proper implementation of fromError toError, clientOutputTransformStream no longer outputs error.data, but rather error directly # This is the commit message #15: fix: jest fix for ErrorRPCRemote # This is the commit message #16: wip toError fromError fix: proper implementation of fromError toError, clientOutputTransformStream no longer outputs error.data, but rather error directly fix: changed rpcClient toError implementation fix: changing ErrorRPCRemote constructor to be in-line with toError error creation constructor fix: jest fix for ErrorRPCRemote fix: fixing exports fix: RPC errors now correctly extend AbstractError fix: removed old events fix: cleaned up imports feat: client has toError as parameter fix: removed type from JSONError obj fix: startStop constructor correctly used fix: infinity is definitely not == 1 minute chore: rename variable
Description
This PR factors out the RPC functionality out of Polykey. It needs to work with https://github.com/MatrixAI/js-ws. In fact
@matrixai/ws
can be adevDependency
in order to demonstrate the integration between WS streams and RPC. But this is not set in stone yet. We have to see what is necessary - trial by fire.TBD - flesh out this spec by writing up all of the relevant classes and modules you're going to need. For example
RPCClient
,RPCServer
... etc.Issues Fixed
rpc
handlers abstract arrow function properties. #5RPC
system #7Tasks
Phase 1: Pre-Migration Assessment (Day 1)
Phase 2: Environment Setup and Initial Migration (Day 1)
Phase 3: Adaptation and Refactoring (Days 2-3)
Phase 4: Integration and Advanced Testing (Day 4)
Phase 5: Final Touches and PR
Final checklist