-
Notifications
You must be signed in to change notification settings - Fork 919
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
Cleanup OsdUrlStateStorage subscription in TopNav #9167
base: main
Are you sure you want to change the base?
Conversation
❌ Invalid Prefix For Manual Changeset CreationInvalid description prefix. Found "fix". Only "skip" entry option is permitted for manual commit of changeset files. If you were trying to skip the changelog entry, please use the "skip" entry option in the ##Changelog section of your PR description. |
@@ -49,7 +49,7 @@ import { validateTimeRange } from '../timefilter'; | |||
* @param OsdUrlStateStorage to use for syncing and store data | |||
* @param syncConfig app filter and query | |||
*/ | |||
export const connectStorageToQueryState = async ( | |||
export const connectStorageToQueryState = ( |
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.
will this function ever return anything other than the unsub callback function, besides it reaching the catch
block? Several questions regarding that:
- Based on the call pattern that you provided on the usage of the returning callback function, can't we just unsub from the end of this function instead of wrapping it with a
useEffect
by the caller? - If some
subs
were made and then getting to thecatch
block for some error, don't we want to unsub from thecatch
as well?
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 the intended behaviour hear is let the scope where invokes connectStorageToQueryState
to maintain the life cycle of the subscription.
It make senses to me to unsub in the catch
block, but currently the subscription is building at the end of the try
block, it's unlikely to have any lingering subscription if it reach catch
block.
@@ -65,7 +65,7 @@ export const TopNav = ({ opts, showSaveQuery, isEnhancementsEnabled }: TopNavPro | |||
? getTopNavLinks(services, inspectorAdapters, savedSearch, isEnhancementsEnabled) | |||
: []; | |||
|
|||
connectStorageToQueryState( | |||
const unSub = connectStorageToQueryState( |
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.
Change LGTM. One thing (I know it's outside of the scope of this PR) I wanted to discuss is that we're relying on folk's best intention and understanding of connectStorageToQuery
to unsubscribe and avoid these memory leaks.
It may be nice to introduce a hook or HOC wrapper, which subscribes on mount and unsubscribes on unmount to abstract the subscription from the consumer.
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.
+1 Good idea, any suggestion which folder to put this hook in?
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.
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.
Agree with that, should we move the connectStorageToQueryState
into a useEffect? and we can unsubscribe the change inside that useEffect hook as well.
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 have created the hook under same folder of plugins/data
, since it's been using from src/plugins/discover/...
and src/plugins/vis_builder/...
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9167 +/- ##
==========================================
- Coverage 61.01% 61.01% -0.01%
==========================================
Files 3812 3812
Lines 91385 91393 +8
Branches 14438 14440 +2
==========================================
+ Hits 55762 55763 +1
- Misses 32065 32073 +8
+ Partials 3558 3557 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
do you mind signing the commit on push? |
do you have the changelog bot setup i think we can have a changelog for this |
src/plugins/data/public/query/state_sync/connect_to_query_state.ts
Outdated
Show resolved
Hide resolved
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.
question:
do you think we should put this in a lib folder within the state_sync folder or would that be just too messy? i see some folders have it but i dont think there is a consistency within the project.
query: boolean; | ||
dataSet?: boolean; | ||
}, | ||
uiSettings?: CoreStart['uiSettings'] |
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.
what about uiSettings?
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's a unused variable
const { selected: indexPattern } = useIndexPatterns(); | ||
const [config, setConfig] = useState<TopNavMenuData[] | undefined>(); | ||
const originatingApp = useTypedSelector((state) => { | ||
return state.metadata.originatingApp; | ||
}); | ||
|
||
useConnectStorageToQueryState(services.data.query, services.osdUrlStateStorage, { |
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.
without diving too deep, do we know if the query state is changed and navigate to visbuilder if this gets set to after the the index patterns does it cause a difference in the selected: indexPattern?
…in TopNav Update src/plugins/data/public/query/state_sync/connect_to_query_state.ts Co-authored-by: Kawika Avilla <[email protected]> Signed-off-by: Joey Liu <[email protected]> Changeset file for PR opensearch-project#9167 created/updated
Description
OsdUrlStateStorage
subscription inTopNav
is not properly cleaned up, which is causingScopedHistory
throwing error and potential memory leak.Issues Resolved
-fixes #5476
Screenshot
Before
Screen.Recording.2025-01-09.at.1.19.16.PM.mp4
After
Screen.Recording.2025-01-09.at.1.13.41.PM.mp4
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration