Fix UdpClient.EnableBroadcast not preventing broadcast sends#124482
Fix UdpClient.EnableBroadcast not preventing broadcast sends#124482liveans merged 4 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
🤖 Copilot Code Review — PR #124482Holistic AssessmentMotivation: The issue is real and well-documented (#118055). Approach: Tracking whether the user explicitly set Summary: Detailed Findings❌ Test compilation error —
|
When a user explicitly sets EnableBroadcast to false, CheckForBroadcast() should respect that choice and not auto-enable the broadcast socket option. Fixes dotnet#118055 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Group related broadcast fields together, following the existing convention in UDPClient.cs. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…butes - Consolidate ExplicitlyDisabled and ExplicitlyEnabledThenDisabled tests into a single [Theory] with [InlineData(false/true)] - Remove redundant [SkipOnPlatform(TestPlatforms.Wasi)] attributes since IsThreadingSupported already returns false on WASI Co-Authored-By: Claude Opus 4.6 <[email protected]>
e66e7fa to
988626d
Compare
|
Addressed the feedback — consolidated the two "explicitly disabled" tests into a One note: Also rebased on latest |
…readingSupported Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Correction on my previous comment: the Copilot review was right — the property is |
|
@dotnet-policy-service agree |
|
Hi — just checking in. I addressed all the review feedback on March 5 (consolidated tests into a |
Hello, thanks for checking in, no action is needed from your side for now. I'll review this PR today. |
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/ba-g failures unrelated |
Summary
Fixes #118055
UdpClient.CheckForBroadcast()unconditionally auto-enables theBroadcastsocket option when sending toIPAddress.Broadcast, even when the user has explicitly setEnableBroadcast = false. This PR makesCheckForBroadcast()respect the user's explicit choice.Changes
_isBroadcastSetByUserfield to track whetherEnableBroadcasthas been explicitly set by the userCheckForBroadcast()to skip auto-enable when the user has explicitly setEnableBroadcastNote: The pre-existing
_isBroadcastflag is not reset when theClientsocket is replaced via the property setter. The new_isBroadcastSetByUserflag follows this same pattern for consistency. Resetting state on socket replacement could be a follow-up improvement.Testing
EnableBroadcast_ExplicitlyDisabled_NotAutoEnabled— verifies that explicitly disabling broadcast prevents auto-enable on broadcast sendEnableBroadcast_ExplicitlyEnabledThenDisabled_NotAutoEnabled— verifies the toggle case (enable → disable) also prevents auto-enableEnableBroadcast_NotExplicitlySet_AutoEnabled— verifies backward compatibility: auto-enable still works when the user hasn't set the property