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

feat: replace CLS with ALS, enable ALS by default, discourage unmanaged transactions #15292

Merged
merged 11 commits into from Nov 19, 2022

Conversation

ephys
Copy link
Member

@ephys ephys commented Nov 16, 2022

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

Closes #15291
Closes #13742

This PR drops CLS in favor of using node's built-in AsyncLocalStorage.

The AsyncLocalStorage is now per Sequelize instance instead of global. It never made sense for this option to be global.

It also enables ALS transactions by default. They can be disabled by setting disableAlsTransactions to true in Sequelize's options.

Finally, in order to discourage using unmanaged transactions (which are easy to misuse), this PR removes the ability to get an unmanaged transaction by not providing a callback to sequelize.transaction().
Unmanaged transactions are now started using sequelize.startUnmanagedTransaction() instead.

Todos

  • Open a PR to update the documentation website

@ephys ephys added topic: cls For issues and PRs. Everything that involves CLS funded labels Nov 16, 2022
@ephys ephys self-assigned this Nov 16, 2022
@ephys ephys marked this pull request as ready for review November 17, 2022 18:02
@ephys ephys requested a review from a team November 17, 2022 18:02
fzn0x
fzn0x previously approved these changes Nov 18, 2022
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Looks good! Don't forget to remove cls-hooked from package.json, apart from that it's just a few typos

test/integration/als.test.ts Outdated Show resolved Hide resolved
test/integration/als.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@fzn0x fzn0x left a comment

Choose a reason for hiding this comment

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

This is interesting

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

I found a last reference to CLS here;

describe('_logQuery', () => {

But we should be good after that

@ephys
Copy link
Member Author

ephys commented Nov 18, 2022

I don't know why that's called CLS but it doesn't seem to be related to Continuation local storage

@WikiRik
Copy link
Member

WikiRik commented Nov 18, 2022

Maybe rename it to customQuery?

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

We can do the rename in a different PR

@ephys
Copy link
Member Author

ephys commented Nov 19, 2022

Yes let's leave it as is, we'll update the test suite when we migrate it and/or query.js to TypeScript

@WikiRik WikiRik merged commit 4cd43a4 into main Nov 19, 2022
@WikiRik WikiRik deleted the ephys/als branch November 19, 2022 12:06
@OmriSama
Copy link

The v7 alpha documentation still mentions cls-hooked; is it going to be updated?

@OmriSama OmriSama mentioned this pull request May 17, 2023
5 tasks
@ephys
Copy link
Member Author

ephys commented May 18, 2023

It is, the update is in sequelize/website#419, which I need to update & get merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
funded topic: cls For issues and PRs. Everything that involves CLS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate CLS to AsyncLocalStorage Add type for Sequelize.useCLS parameter
5 participants