-
Notifications
You must be signed in to change notification settings - Fork 6
fix: Add Source Filtering to ChromeRuntimeReader for Multi-Endpoint Support #215
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
Conversation
| if (message.target !== this.#target || message.source !== this.#source) { | ||
| return; | ||
| } |
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 think returning is acceptable behavior but we should still console.info for the time being. See this comment for a prior discussion suggesting a convention for logger methods. This will result in logger output under regular use, but I think we would rather taper that off via log levels than not have the feedback at all.
Also, since this PR specifies the Reader and Writer to a specific directed edge of our comms network, we should consider using the local and remote nomenclature here to specify the edge, instead of target which specifies either the local or remote node depending on whether the stream is for reading or writing.
| if (message.target !== this.#target || message.source !== this.#source) { | |
| return; | |
| } | |
| if (message.target !== this.#local || message.source !== this.#remote) { | |
| console.info( | |
| `ChromeRuntimeReader received message for unexpected target: ${stringify( | |
| message, | |
| )}`, | |
| ); | |
| return; | |
| } |
The local/remote names mirror what is done with the BaseDuplexStream.
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.
logging there will be misleading imo since runtime.onMessage listener essentially catches all messages, but I'm ok if we use console.debug so they appear in verbose mode.
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.
After reading this reference on log levels I agree with your assessment that debug is the right method here. I think we would benefit from a convention for when to use each of these methods. I added a discussion issue for the topic.
grypez
left a comment
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 get why we need to do this. Although the messages use source and target properties, I think the newly specified Reader and Writer should follow the local / remote convention established in the DuplexStream.
This is not exactly the case and it can lead to confusion, since, for |
bd915aa to
6481318
Compare
grypez
left a comment
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.
for
ChromeRuntimeReaderthetargetis thelocalTargetbut forChromeRuntimeWriterthetargetis theremoteTargetof theChromeRuntimeDuplexStream. I think what we have now is clearer.
Well, the difference is that with the source/target nomenclature the user of Reader and Writer should permute source and target at construction. That is, when setting up a Reader and Writer at node A to talk to node B, the Reader should have target A and source B while the Writer should have target B and source A. With the local and remote nomenclature, the user passes local A and remote B to both the Reader and Writer.
Before this PR we were implicitly naming directed edges of the network based on assumptions about Reader and Writer. After this PR we will be naming the directed edges explicitly by both the head and tail nodes, but which node is the head and which is the tail depends on whether we are using a Reader or Writer. I think since we will never be able to instantiate A's reader and B's writer in the same realm, we are better served aligning the arguments for the A --> B writer with the B --> A reader, i.e. using the local/remote convention.
But this is all merely a convention and the code works. I don't think I can make any deeper argument for my view so I'll approve. Thanks for reading!
Closes #214
This PR resolves an issue with multiple
ChromeRuntimeDuplexStreaminstances using the same endpoint (e.g., offscreen), in our case when there were multiple connections involveoffscreen, such as betweenbackgroundandoffscreenand alsodevtoolsandoffscreen.For example, when
devtoolsandbackgroundboth haveoffscreenas a target, there was no way to tell where the messages were coming from, leading to unexpected errors. By adding a source filter, we can now differentiate the messages, so each connection is handled correctly.Changes:
ChromeRuntimeReaderbased on the source of incoming messages. This allows us to differentiate between connections and prevent unexpected message errors.ChromeRuntimeWriterto include the source in each message, ensuring that messages are directed to the correct target in multi-connection setups.