-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
NullReferenceException hides actual exception #23157
Comments
Thanks!
I believe so. This seems to be the case for some |
|
@smitpatel Thanks to bringing my attention back to the issue. As it turns out, we just had a bug in our public class MySqlCompatibilityExpressionVisitor : ExpressionVisitor
{
protected override Expression VisitExtension(Expression extensionExpression)
=> extensionExpression switch
{
RowNumberExpression rowNumberExpression => VisitRowNumber(rowNumberExpression),
CrossApplyExpression crossApplyExpression => VisitCrossApply(crossApplyExpression),
OuterApplyExpression outerApplyExpression => VisitOuterApply(outerApplyExpression),
ExceptExpression exceptExpression => VisitExcept(exceptExpression),
IntersectExpression intersectExpression => VisitIntercept(intersectExpression),
ShapedQueryExpression shapedQueryExpression => shapedQueryExpression.Update(
Visit(shapedQueryExpression.QueryExpression),
shapedQueryExpression.ShaperExpression), // <-- missing the Visit() call
_ => base.VisitExtension(extensionExpression)
};
protected virtual Expression VisitCrossApply(CrossApplyExpression crossApplyExpression)
=> CheckSupport(crossApplyExpression, _options.ServerVersion.SupportsCrossApply);
} This was not an issue when processing the expression visitor at the very end of the pipeline, because |
Would it be possible to backport that fix for 5.0.x? The change looks quite significant, perhaps it's possible to backport just the part that affects the |
@Obi-Dann Can you explain a bit more how the type of exception thrown is impacting you here? (This will help us determine if this issue is something we will patch.) |
@ajcvickers We just came to the same issue - strange new exceptions appearing in logs do not make production support happy |
Is it fixed in 5.0.* with Npgsql 5.0.7? |
@freerider7777 No, it was only fixed in 6.0.0-preview1 and later |
@AndriySvyryd It's a pity... Very easy to simulate - I connect to office network using VPN. If I disconnect from VPN when running my asp.net core service, I receive this errors in logs which hide the real problem... Is there a workaround? It's critical for production to understand what is the real problem, please fix it... |
@freerider7777 A quick solution for finding the underlying issue is to implement a FirstChanceException Event handler. It could log all exceptions (that includes those that are thrown and caught internally). The exception you are looking for should then be logged before the |
@lauxjpn Thanks for that! I think it would double the logs... Maybe I write a new issue, that EF 5.* cannot be used in production with such problems? |
Could be the case, depending on how many internal exceptions are being thrown in your app (in EF Core and providers, it is not common to throw internal exceptions, except when checking for database existence).
If you feel strongly about it, it might be a good idea. After all, being able to correctly diagnose an issue is an important thing. But the EF Core team will be able to give you a better estimated, what the chances for a 5.0 backport are. |
@Obi-Dann Do you have a solution for this issue with EF5 (maybe a patch to compile it from sources)? |
@freerider7777 No, not really. We haven't migrated to EF 5 because of performance issues with split queries that require us to rewrite the majority of the queries. |
@Obi-Dann Thanks... Are you now using 3.1? What performance issues did you have? As far as I understand EF 3.1 uses single queries and you can use it in EF5, why switch to split queries? |
We're on EF 2 still because we have a lot of split queries (that was the default behaviour) and it isn't really a priority atm to rewrite them. But because of #24808 we can't keep using split queries in the same way as they were in ef 2 |
We're also using 2.2, and I've also written a couple of issues on inefficient query changes (more inner queries than 2.2). MS drives us to the idea of using more stable libraries... But we need interceptors, so now we're examining all the produced queries, maybe it's better to write them in sql from the beginning... |
The change from EF Core 2.2 to 3.0 was huge and pretty much the last chance for the EF Core team gain full control over the query pipeline, which they did. Since 3.0, EF Core in general and the query pipeline in particular have been very stable when it comes to upgrading, at least that is the case for the applications that I am maintaining, where I did not have to change a thing in regards to query performance. In fact, while I believe that none of my queries got slower, some got faster due to more man hours spent on query optimization by the EF Core team and provider maintainers since 3.0. So in my experience, once you have made the major jump from 2.2 to 3.0/3.1/5.0/6.0 (which can be daunting), you are unlikely to encounter significant upgrade issues in the future.
That is a legitimate question. In most projects, I automatically measure at least the time of all major operations (e.g. Web API calls) and the time of all query executions, as part of my application infrastructure (I would do this with any technology stack really, not just when it comes to EF Core). Then its just a matter of establishing a value of what can be considered as "fast enough" and checking the actual execution time against it. However, it is also a popular approach to use Dapper for all the read only querying (so your SQL gets executed exactly how you wrote it) and then EF Core for insert/update/delete operations (so you don't have to track those yourself). |
Hehe... Let us hope for this :) We're with MS technologies for 20+ years, with EF for 10 (like that) years and they always seem "moving ground" :))) EF was created in 2008 and still not stabilized (of course moving to .Net Core took place and so on and so on, but simple joins with "Include" still not in good shape...) And mostly - it's a pity that split queries (seemed like compatibility with 2.2) are useless for now... |
Yeah, there has definitely been some movement in technologies over the year and Microsoft has bit of a track record to burn through certain technologies fast. However, EF Core has its own code base, is build from scratch, and while similar in concept to EF, they are not the same technology. So my opinion above is really only targeted at EF Core. Once you upgrade to at least 3.0, there are only very few breaking changes and those are usually only relevant to a small user group. The EF Core team is of course implementing new features and improving existing ones in major releases, but has also around 100K tests to ensure, that existing stuff does not break. So the general stability of the EF Core is very high. As for split queries, they generally work quite nicely and seem to have a broader scope as the did back in 2.2, even though certain cases that worked more efficiently back in 2.2. are now not as efficient anymore as they were back then. Those are the potential cases where, if you encounter performance issues, you either have to split/rewrite the query manually yourself, or automate the process with some code. There is this old Microsoft saying, that products are only really usable after reaching versions 3. So I guess it was quite clever of the EF team back then, to directly start with EF4. 😄 |
This should be stated with big letters on first pages of the docs :) (BTW first EF was 3.5 which was unusable...) |
For some MySQL database server implementations (e.g. MariaDB or MySQL < 8.0), unsupported expressions like
OUTER APPLY
cannot be translated. We throw late in the query pipeline (inMySqlParameterBasedSqlProcessor
), because EF Core might still decide to use some unsupported expressions after aRelationalQueryTranslationPostprocessor
implementation has been called.The following exception e.g. is raised by the
NorthwindSplitIncludeQueryMySqlTest.Include_collection_with_outer_apply_with_filter
test. The exception itself is expected and we expect it to be propagated all the way to the user:However, it results in a
NullReferenceException
for_resultCoordinator.DataReaders
here, which is then propagated to the user instead of our actual exception:efcore/src/EFCore.Relational/Query/Internal/SplitQueryingEnumerable.cs
Line 219 in 551c58a
Include provider and version information
EF Core version:
5.0.0-rc.1
The text was updated successfully, but these errors were encountered: