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

Risk using async trigger behind a sync SaveChanges() call? #127

Closed
benmccallum opened this issue Nov 18, 2021 · 4 comments
Closed

Risk using async trigger behind a sync SaveChanges() call? #127

benmccallum opened this issue Nov 18, 2021 · 4 comments

Comments

@benmccallum
Copy link
Contributor

Hey! We've still got plenty of sync SaveChanges() calls in our codebase that we're slowly getting rid of but it did make me wonder whether there's a risk to writing an async trigger behind a sync call.

Before we dive in fully we might need to eliminate all our legacy sync SaveChanges() calls.

@benmccallum
Copy link
Contributor Author

benmccallum commented Nov 18, 2021

cc: @anthony-keller

@koenbeuk
Copy link
Owner

@benmccallum

There is indeed a risk as calls to SaveChanges will invoke Triggers and wait for the results by blocking the caller thread. This will cause a deadlock when you're calling from a UI thread and potentially causes a deadlock when you're calling from a ThreadPool thread. The latter is possible but rare and will only occur when the load on the thread pool has been maxed out. Still, it may be safer to eliminate all sync calls to SaveChanges first.

Hope this helps!

@benmccallum
Copy link
Contributor Author

Thanks @koenbeuk , good to know. I think I might make a concerted effort to async all our things to be sure.

It might be worth linking this issue from a disclaimer on the readme/docs if you think it warrants it.

@koenbeuk
Copy link
Owner

@benmccallum I'm open for that. Would you mind issuing a PR?

benmccallum added a commit to benmccallum/EntityFrameworkCore.Triggered that referenced this issue Dec 6, 2021
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

No branches or pull requests

2 participants