-
Notifications
You must be signed in to change notification settings - Fork 9
Fix message ports not being closed when proxy is relased #6
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -396,7 +396,7 @@ function closeEndPoint(endpoint: Endpoint) { | |
| } | ||
|
|
||
| export function wrap<T>(ep: Endpoint, target?: any): Remote<T> { | ||
| const pendingListeners : PendingListenersMap = new Map(); | ||
| const pendingListeners: PendingListenersMap = new Map(); | ||
|
|
||
| ep.addEventListener("message", function handleMessage(ev: Event) { | ||
| const { data } = ev as MessageEvent; | ||
|
|
@@ -424,11 +424,12 @@ function throwIfProxyReleased(isReleased: boolean) { | |
| } | ||
| } | ||
|
|
||
| function releaseEndpoint(ep: Endpoint) { | ||
| return requestResponseMessage(ep, new Map(), { | ||
| function releaseEndpoint(ep: Endpoint, pendingListeners?: PendingListenersMap) { | ||
| return requestResponseMessage(ep, pendingListeners || new Map(), { | ||
| type: MessageType.RELEASE, | ||
| }).then(() => { | ||
| closeEndPoint(ep); | ||
| pendingListeners?.clear(); | ||
defunctzombie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
|
|
@@ -486,8 +487,7 @@ function createProxy<T>( | |
| } | ||
| propProxyCache.clear(); | ||
| unregisterProxy(proxy); | ||
| releaseEndpoint(ep); | ||
| pendingListeners.clear(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the issue that clearing the listeners here is premature because the Or is it important to pass
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that's the important bit. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So why do we allow pendingListeners to be undefined? In what situation is that ok?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was necessary when releasing the endpoint when the proxy is garbage collected. However, thinking about this more, we should also have access to the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a commit that changes the |
||
| releaseEndpoint(ep, pendingListeners); | ||
| isProxyReleased = true; | ||
| }; | ||
| } | ||
|
|
@@ -647,6 +647,6 @@ function requestResponseMessage( | |
| ep.start(); | ||
| } | ||
| ep.postMessage({ id, ...msg }, transfers); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.