fix(core): fix race condition in resource()#59851
Closed
alxhub wants to merge 1 commit intoangular:mainfrom
Closed
fix(core): fix race condition in resource()#59851alxhub wants to merge 1 commit intoangular:mainfrom
alxhub wants to merge 1 commit intoangular:mainfrom
Conversation
JeanMeche
reviewed
Feb 4, 2025
ce993a4 to
f56af81
Compare
The refactoring of `resource()` to use `linkedSignal()` introduced the potential for a race condition where resources would get stuck and not update in response to a request change. This occurred under a specific condition: 1. The request changes while the resource is still in loading state 2. The resource resolves the previous load before its `effect()` reacts to the request change. In practice, the window for this race is small, because the request change in (1) will schedule the effect in (2) immediately. However, it's easier to trigger this sequencing in tests, especially when one resource depends on the output of another. To fix the race condition, the resource impl is refactored to track the request in its state, and ignore resolved values or streams for stale requests. This refactoring actually makes the resource code simpler and easier to follow as well. Fixes angular#59842
f56af81 to
3ea10b4
Compare
pkozlowski-opensource
approved these changes
Feb 5, 2025
Member
pkozlowski-opensource
left a comment
There was a problem hiding this comment.
LGTM
Reviewed-for: public-api
Reviewed-for: fw-core
thePunderWoman
approved these changes
Feb 5, 2025
Contributor
thePunderWoman
left a comment
There was a problem hiding this comment.
reviewed-for: public-api
Member
Author
|
This PR was merged into the repository by commit b592b1b. The changes were merged into the following branches: main |
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
The refactoring of `resource()` to use `linkedSignal()` introduced the potential for a race condition where resources would get stuck and not update in response to a request change. This occurred under a specific condition: 1. The request changes while the resource is still in loading state 2. The resource resolves the previous load before its `effect()` reacts to the request change. In practice, the window for this race is small, because the request change in (1) will schedule the effect in (2) immediately. However, it's easier to trigger this sequencing in tests, especially when one resource depends on the output of another. To fix the race condition, the resource impl is refactored to track the request in its state, and ignore resolved values or streams for stale requests. This refactoring actually makes the resource code simpler and easier to follow as well. Fixes angular#59842 PR Close angular#59851
14 tasks
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The refactoring of
resource()to uselinkedSignal()introduced the potential for a race condition where resources would get stuck and not update in response to a request change. This occurred under a specific condition:effect()reacts to the request change.In practice, the window for this race is small, because the request change in (1) will schedule the effect in (2) immediately. However, it's easier to trigger this sequencing in tests, especially when one resource depends on the output of another.
To fix the race condition, the resource impl is refactored to track the request in its state, and ignore resolved values or streams for stale requests. This refactoring actually makes the resource code simpler and easier to follow as well.
Fixes #59842