Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Merge | Merge netfx-specific exception handling#3179

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
benrr101 merged 3 commits intodotnet:mainfromedwardneal:merge/exception-handling
Mar 6, 2025

Conversation

edwardneal
Copy link
Contributor

Contributes to#2965 and#1261.

This PR merges the exception handling for ThreadAbortException, StackOverflowException and OutOfMemoryException between .NET Core and .NET Framework.

Following this PR, it becomes fairly trivial to merge SqlBulkCopy, SqlDataReader and SqlTransaction.

Given the number of indentation changes from try/catch blocks, I'd recommend switching off whitespace when checking the diff - it eliminates around a third of it.

I'd appreciate a CI run for this.

Merge exception handling for SqlBulkCopy, SqlCommandBuilder, SqlDataReader, SqlInternalConnection, SqlTransaction and (partially) SqlConnection
@paulmedynski
Copy link
Contributor

/azp run

@azure-pipelinesAzure Pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@benrr101benrr101 left a comment

Choose a reason for hiding this comment

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

I'm a bit on the fence about this one, so I'd like to hear your thoughts before approving.

  1. My understanding of the constrained execution regions is that checking forOutOfMemoryException,StackOverflowException,ThreadAbortException is only required if there is a constrained execution region. I'm a bit concerned if this is a bit of a behavior change.
  2. It looks to me that the plan is to have put thebestEffortCleanup in both netfx and netcore, but make it such that the netcoreBestEffortCleanup implementation does nothing. I'm not a huge fan of this, since without digging into the implementations ofBestEffortCleanup, it won't be obvious nothing is happening. I get that it'd be easier to merge the codebases, but I'm worried it won't be clear what's actually happening.

This isn't the first time something like this has come up, so I wonder if maybe we should come up with something that makes it clear the method call is only doing anything when in netfx or netcore. Sorta like howDebug.Assert is expected to only run when it's a DEBUG build.

@codecovCodecov
Copy link

codecovbot commentedFeb 26, 2025
edited
Loading

Codecov Report

Attention: Patch coverage is26.37615% with321 lines in your changes missing coverage. Please review.

Project coverage is 65.92%. Comparing base(0be2756) to head(644ac85).
Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
...core/src/Microsoft/Data/SqlClient/SqlDataReader.cs25.74%225 Missing⚠️
...ore/src/Microsoft/Data/SqlClient/SqlTransaction.cs19.40%54 Missing⚠️
...core/src/Microsoft/Data/SqlClient/SqlConnection.cs16.00%21 Missing⚠️
...etcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs40.00%15 Missing⚠️
.../netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs33.33%6 Missing⚠️

❗ There is a different number of reports uploaded between BASE (0be2756) and HEAD (644ac85). Click for more details.

HEAD has 1 upload less than BASE
FlagBASE (0be2756)HEAD (644ac85)
addons10
Additional details and impacted files
@@            Coverage Diff             @@##             main    #3179      +/-   ##==========================================- Coverage   72.81%   65.92%   -6.90%==========================================  Files         282      279       -3       Lines       59112    59109       -3     ==========================================- Hits        43045    38967    -4078- Misses      16067    20142    +4075
FlagCoverage Δ
addons?
netcore68.78% <25.70%> (-6.74%)⬇️
netfx64.84% <62.50%> (-6.30%)⬇️

Flags with carried forward coverage won't be shown.Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@edwardneal
Copy link
ContributorAuthor

Thanks. The changes at the moment are no-ops, there's no behaviour change. An OutOfMemoryException without CERs means that the CLR's in an undefined state anyway, a StackOverflowException results in the process being killed and netcore doesn't throw ThreadAbortExceptions at all.

What about wrapping every call to BestEffortCleanup in#if NETFRAMEWORK? I hadn't originally wanted to do that, but that was purely cosmetic - I didn't want to leave conditional compilation scattered across the codebase. It'd be a little clearer than having a stub method though.

@benrr101
Copy link
Contributor

... there's no behaviour change...

I think the only instances where was most concerned about behavior change was when the new catches were added when there wasn't a catch-all exception handler. All the other instances are fine since they basically do the same thing as the catch-all handler.

My understanding, too, is that we really only have the CERs in place to handle situations where SqlClient is being called from SQL Server CLR. The theory being that the CER is there to protect SQL Server from crashing if something goes wrong with SqlClient. Outside of those situations, I don't care as much about cleanup behavior. I suppose my primary issue is whether we'll try to clean things up in netcore that were not being cleaned up before.

What about wrapping every call to BestEffortCleanup in#if NETFRAMEWORK?

Yeah.... that's what I had been doing for the merge I've been working on for SqlTransaction. It's messy as all heck, but it's generally clear that the code is being used or not. I've even been wrapping the extra catch blocks in the same#if. One thing I've done (that nobody's complained or applauded yet) is keep the#if tabbed over the same as the code it's wrapping. It makes it a bit less clumsy.

One experiment I was trying (and this prompted removing the resilience sections) was to use an inline function to implement the meat and potatoes of the method and either call it directly (in netcore) or pass it into a method that wraps it with appropriate CES handling. It appears that by using inline functions, it's only marginally less performant, but cleans up the code a lot. Something like:

publicvoidMyMethod(){voidDoTheStuff(){// stuff}  #ifNETFRAMEWORKcallWithCes(DoTheStuff)  #elseDoTheStuff();  #endif}

of course what would be really nice is if we could just get rid of CERs...

@edwardneal
Copy link
ContributorAuthor

I think the only instances where was most concerned about behavior change was when the new catches were added when there wasn't a catch-all exception handler.

I understand. These three exceptions fall into two groups though:

  1. Never thrown in netcore (which means the catch is unreachable and any change in behaviour is a moot point)
  2. Thrown where the internal state of the netcore CLR is in the process of terminating as a result of a lack of memory (which kills the connection anyway)

Yeah.... that's what I had been doing for the merge I've been working on for SqlTransaction. It's messy as all heck, but it's generally clear that the code is being used or not. I've even been wrapping the extra catch blocks in the same#if.

I'll do that, thanks. I think BestEffortCleanup is the best place to draw the line, since its body relies on details of TdsParserStateObject which can't be merged and the catch blocks are functionally no-ops.

Wrapped each call to SqlInternalConnection.BestEffortCleanup in #if, rather than having an empty BestEffortCleanup method.
These were part of the netfx exception handling
Copy link
Contributor

@benrr101benrr101 left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this and rationale for the change 🚀

@benrr101
Copy link
Contributor

/azp run

@azure-pipelinesAzure Pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@cheenamalhotracheenamalhotra added this to the7.0-preview1 milestoneMar 4, 2025
@benrr101benrr101 merged commit42a1999 intodotnet:mainMar 6, 2025
123 checks passed
@edwardnealedwardneal deleted the merge/exception-handling branchMarch 6, 2025 19:52
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@benrr101benrr101benrr101 approved these changes

@cheenamalhotracheenamalhotracheenamalhotra approved these changes

@paulmedynskipaulmedynskiAwaiting requested review from paulmedynski

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
6.1-preview1
Development

Successfully merging this pull request may close these issues.

4 participants
@edwardneal@paulmedynski@benrr101@cheenamalhotra

[8]ページ先頭

©2009-2025 Movatter.jp