Skip to content
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

Ensure context in Open stays open #4

Merged
merged 4 commits into from
Mar 21, 2022
Merged

Ensure context in Open stays open #4

merged 4 commits into from
Mar 21, 2022

Conversation

lovromazgon
Copy link
Member

The context passed to the plugin in Open should stay open even after the function returns because the context can be used to spawn background jobs that fetch records.

Comment on lines +113 to +114
ctxOpen := context.Background()
ctxOpen, a.openCancel = context.WithCancel(ctxOpen)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, why don't we simply do ctxOpen, a.openCancel = context.WithCancel(context.Background())?

Or maybe even ctxOpen, a.openCancel = context.WithCancel(ctx)?

Copy link
Member Author

@lovromazgon lovromazgon Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First option won't work unless you declare ctxOpen a line before with var ctxOpen context.Context, not really an improvement IMO.

Second option is essentially what we did before but it had a flaw - the context could be canceled even after Open returns (and it actually happens), so that context is then not suitable for spawning long-running goroutines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! TIL a bit more about multiple short var declarations.: )

@lovromazgon lovromazgon merged commit c7287fb into main Mar 21, 2022
@lovromazgon lovromazgon deleted the lovro/open-ctx branch March 21, 2022 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants