fix: remove force-unwrap on session dictionary in DefaultNetworkService - #1787
Merged
jglogan merged 1 commit intoJun 23, 2026
Merged
Conversation
jglogan
reviewed
Jun 23, 2026
jglogan
left a comment
Contributor
There was a problem hiding this comment.
@SEPURI-SAI-KRISHNA See the suggested fix for this force-try.
| } | ||
| } | ||
| allocationsBySession[session]!.append((hostname: hostname, index: index)) | ||
| allocationsBySession[session]?.append((hostname: hostname, index: index)) |
Contributor
There was a problem hiding this comment.
This approach to L98-104 would be better:
let isNewSession = allocationsBySession[session] == nil
allocationsBySession[session, default: []].append((hostname: hostname, index: index))
if isNewSession {
await session.onDisconnect { [weak self] in
await self?.releaseSession(session)
}
}
Contributor
Author
There was a problem hiding this comment.
I have made the changes. please check. Thank you !
jglogan
requested changes
Jun 23, 2026
SEPURI-SAI-KRISHNA
force-pushed
the
fix/network-service-dict-force-unwrap
branch
3 times, most recently
from
June 23, 2026 04:53
da2da1d to
c8d6756
Compare
SEPURI-SAI-KRISHNA
force-pushed
the
fix/network-service-dict-force-unwrap
branch
from
June 23, 2026 04:55
c8d6756 to
ef8e0b5
Compare
Code Coverage
|
jglogan
approved these changes
Jun 23, 2026
jglogan
left a comment
Contributor
There was a problem hiding this comment.
@SEPURI-SAI-KRISHNA approved, thank you!
Contributor
Author
|
@jglogan Thanks for your support and patience. Would love to contribute further. |
stephenlclarke
pushed a commit
to stephenlclarke/container
that referenced
this pull request
Jun 24, 2026
…ce (apple#1787) - Instead of using force-unwrap to append to a list-valued dictionary entry that should always exist, assign the value with a default fallback and append to the (non-optional) result.
jianliang00
pushed a commit
to jianliang00/container
that referenced
this pull request
Aug 28, 2026
…ce (apple#1787) - Instead of using force-unwrap to append to a list-valued dictionary entry that should always exist, assign the value with a default fallback and append to the (non-optional) result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Motivation and Context
In
DefaultNetworkService.allocate, the dictionary entry forsessionis initialized at line 98 if nil, then immediately force-unwrapped at
line 104 with
allocationsBySession[session]!.append(...).While the actor serializes access and the entry should always exist at
that point, the force-unwrap is an unnecessary crash risk if the
invariant is ever broken. Replaced with optional chaining (
?) whichsilently no-ops rather than crashing.
Testing