Promote CA2000 to warning and resolve existing disposal diagnostics
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with the root .editorconfig entry for CA2000 and reproduce the reported baseline with dotnet build --no-restore -v:minimal on the specified revision. Work through the listed source locations by ownership category, beginning with the seven straightforward cleanup candidates; use focused regression tests for each behavior sensitive change. Done means the diagnostics are fixed or narrowly justified, ownership lifetimes and async paths remain correct, and the applicable build matrix passes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Goal
Promote dotnet_diagnostic.CA2000.severity from suggestion to warning in the root .editorconfig, resolving or narrowly documenting existing diagnostics first.
CA2000 detects disposable objects whose cleanup or ownership transfer is not established by analysis. Normal builds treat warnings as errors, so this promotion will enforce the rule during builds rather than leaving it as an informational IDE diagnostic.
Do not resolve diagnostics by adding using indiscriminately: several resources escape to callers, belong to pools, or remain in use by asynchronous continuations.
Reproduction and scope
- Baseline inspected:
5d9001ea2423e850d3fc6d07f822e84bd0004352(Handle authentication configuration failures independently (#4821)), on development branchdev/paul/aot/phase-1.3. - Local change: set CA2000 severity to
warning. - Command:
dotnet build --no-restore -v:minimal. - Environment: Linux, .NET SDK
10.0.402, default Debug configuration. - Result: failed with 32 distinct CA2000 source locations. The build summary reported 65 errors, comprising repeated build-variant diagnostics and the orchestration failure.
- This is a branch-specific initial inventory, not proof of the complete repository backlog. The build stopped at the driver failure; subsequent projects, other configurations, and platform-specific paths can reveal additional diagnostics. Line numbers below refer to the inspected revision.
- Analysis was read-only; none of the proposed fixes has been implemented or regression-tested.
All source paths below are relative to src/Microsoft.Data.SqlClient/src/Microsoft/Data/.
Initial triage
1. Straightforward local cleanup: 7 locations
Good candidates for a first behavior-preserving cleanup, subject to focused validation.
| File and line | Proposed treatment |
|---|---|
SqlClient/VirtualSecureModeEnclaveProviderBase.cs:435 |
Add scoped disposal of the local X509Chain. No chain object escapes certificate verification. |
SqlClient/ManagedSni/SniCommon.netcore.cs:138 |
Add scoped disposal of the local X509Chain after its status has been inspected. |
SqlClient/SqlDependencyListener.cs:359 |
Dispose the temporary SqlCommand with a using declaration. It does not own the connection or transaction. |
SqlClient/Server/ValueUtilsSmi.cs:448, 2132, 2521, 3016 |
Dispose temporary SmiGettersStream/SmiSettersStream wrappers. Their current implementations inherit base stream disposal without custom cleanup. Keep copied streams alive when they are returned through SqlBytes or SqlXml; distinguish the temporary source from its returned copy. |
2. Small but not mechanical: 7 locations
| File and line | Required care |
|---|---|
SqlClient/Server/SqlSer.cs:185, 196 |
BinaryWriter and BinaryReader wrap borrowed streams. Plain using would close the underlying stream. Consider leaveOpen: true and scoped wrapper disposal; verify writer flushing, encoding, and UDT serialization behavior. |
SqlClient/SqlMetaDataFactory.cs:765, 768, 771, 775 |
Tables are loaded and then added to a returned dataset. Dispose on loading/addition failures without prematurely disposing successfully transferred tables. |
SqlClient/ManagedSni/SniTcpHandle.netcore.cs:386 |
Existing finally cleanup handles most paths, but Blocking is set in an object initializer before the local receives the socket. Split allocation from property initialization so a throwing setter cannot bypass local cleanup. Preserve ownership of the successfully returned socket and inspect the success-transfer boundary. |
3. Existing cleanup or intentional ownership: 9 locations
These are candidates for narrowly justified suppressions or analyzer-friendly ownership expression, not automatic additional disposal. Confirm each contract before suppressing.
| File and line | Existing ownership/cleanup |
|---|---|
SqlClient/SqlAeadAes256CbcHmac256Algorithm.cs:193, 195 |
AES providers are deliberately returned to a reuse pool in finally. Disposing them per encryption operation would break reuse. Pool-lifetime cleanup is a separate question. |
SqlClient/SqlCommand.Scalar.cs:58 |
CompleteExecuteScalar already closes the reader in finally. |
SqlClient/SqlMetaDataFactory.cs:220 |
The resulting DataTable is returned to the caller. |
SqlClient/SqlConnection.cs:2914 |
The temporary internal connection already has finally cleanup. |
SqlTypes/SqlFileStream.cs:866 |
Handle ownership passes to FileStream; the catch path disposes an acquired valid handle. A local using would close the successful stream's handle. |
SqlClient/SqlInternalTransaction.cs:300 |
The command runs with returnStream: false; the analyzed path does not create a returned reader. |
SqlClient/Connection/SqlConnectionInternal.cs:2957 |
Inspect the actual transaction request values. The shared request method creates a reader only for GetDTCAddress; ordinary transaction-control requests do not return one. |
SqlClient/Parser/TdsParser.cs:9731 |
The Propagate transaction request does not return a reader, despite the shared method's disposable return type. |
4. Ownership-sensitive work: 9 locations
Require exception-path/lifetime analysis and targeted regression coverage.
| File and line | Work needed |
|---|---|
SqlClient/SqlConnection.cs:1388 |
Establish ownership of the transaction discarded when reconnection forces another begin attempt. Disposal can trigger rollback; preserve the returned transaction and reconnection semantics. |
SqlClient/SqlConnectionFactory.cs:423 |
The non-pooled async-open cancellation source is disposed by a completion continuation. Check failures before that continuation is registered and avoid disposal while scheduled work still uses it. |
SqlClient/SqlSequentialStream.cs:134 |
Normal synchronous/asynchronous completion disposes the linked cancellation source, but synchronous exceptions can bypass that cleanup. Distinguish the newly linked source from the stream-owned disposal source. |
SqlClient/SqlCommand.NonQuery.cs:907 |
Reconnect callbacks already cancel/dispose the timeout source. Verify setup exceptions and timeout/reconnect races before changing ownership. |
SqlClient/SqlCommand.Reader.cs:1679 |
Same reconnect timeout-source ownership concerns as the nonquery path; keep both execution paths consistent. |
SqlClient/SqlCommand.Encryption.cs:628 |
Encryption metadata reader ownership spans synchronous cleanup and asynchronous continuations, plus connection async-count bookkeeping. Avoid premature close or duplicate cleanup. |
SqlClient/SqlCommand.Xml.cs:127 |
Successful ownership transfers through SqlStream to the returned XmlReader. Check failures before transfer: metadata inspection happens outside the completion helper's cleanup try. A method-scoped using would break the returned XML reader. |
SqlClient/Parser/TdsParserStateObject.cs:2943, 3120 |
DEBUG-only delay timers must stay rooted until firing and be disposed afterward. A method-scoped using would cancel the intended delayed operation. Preserve delayed completion, exception propagation, and write-count bookkeeping. |
Suggested implementation sequence
- Land straightforward local cleanup with focused tests.
- Address borrowed-stream wrappers, table construction failures, and socket initialization.
- Document verified ownership false positives using the narrowest appropriate suppression or analyzer-friendly code shape. Do not blanket-disable CA2000.
- Fix and test async, transaction, XML-reader, and debug-timer lifetimes separately.
- Promote CA2000 to
warningand run the complete applicable build matrix to discover and resolve remaining diagnostics.
Acceptance criteria
- Root
.editorconfigsetsdotnet_diagnostic.CA2000.severity = warning. - Existing diagnostics are fixed or narrowly suppressed with an explicit, verified ownership rationale.
- Caller-owned streams, returned readers/tables, pooled crypto providers, and transferred file/socket handles remain usable for their intended lifetimes.
- Exception, cancellation, timeout, reconnection, and ownership-transfer paths clean up correctly without double disposal or premature disposal.
- Regression tests cover behavior-sensitive changes, including sync/async counterparts where applicable.
- Debug-only delayed-write behavior remains correct.
- Full applicable builds pass, including downstream tests/samples/tools, supported target frameworks, and Windows-specific paths; record exact commands and results.
- No global CA2000 suppression or relaxation of normal warnings-as-errors policy is introduced to make the promotion pass.
- Lingua principale
- C#
- Stelle
- 1k
- Fork
- 352
- Merge medio
- 4g 17h
- PR unite (30g)
- 82
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dotnet/SqlClient
-
Sync ExecuteReader on an STA thread deadlocks against a StateChange handler that marshals to the UI thread (OpenAsyncRetry path)Forse di nuovo libera @mdaigle l’ha presa 41 giorni fa e non c’è nessuna pull request aperta. ApertaExternal :link:
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
dotnet/SqlClient#4534 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
Area\Tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
dotnet/SqlClient#4377 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Approval Needed Code Health :pill: Common Project 🚮 Design Review Needed Up-for-Grabs :raised_hands:
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
dotnet/SqlClient#4940 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
Packet multiplexing: async nvarchar(max) read returns corrupted value, throws ArgumentException or spins when the value starts in a packet with header ID 0Forse già presa @cheenamalhotra l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
dotnet/SqlClient#4925 · 4 commenti · 2 reazioni · 2 assegnatari ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
dotnet/SqlClient#4921 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di dotnet/SqlClient
Issue simili
-
Add 'upm' tag on githubAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug mac アプリ: コード アプリ: チャット 優先: 中 要トリアージ
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
yksr-melt/Meltype#1346 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Collect corrected translations in the app, with no GitHub account and the least possible frictionApertalocalization medium ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
hexide-io/HexIDE#2819 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100