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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle cyclic dependency between RCEA and Flags #4285
Conversation
81cbaef
to
fd18e59
Compare
Codecov Report
@@ Coverage Diff @@
## master #4285 +/- ##
============================================
+ Coverage 73.34% 73.36% +0.02%
- Complexity 16967 16992 +25
============================================
Files 1450 1451 +1
Lines 64055 64126 +71
Branches 8046 8068 +22
============================================
+ Hits 46983 47048 +65
- Misses 12978 12981 +3
- Partials 4094 4097 +3
Continue to review full report at Codecov.
|
it/rcea/src/test/java/com/linecorp/armeria/common/CyclicDependencyTest.java
Outdated
Show resolved
Hide resolved
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class CyclicDependencyTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about prefixing Flags
to tell what could have cyclic dependencies.
public class CyclicDependencyTest { | |
class FlagsCyclicDependencyTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot about this comment 😅 Will handle renaming soon
module: rcea
-> flags-cyclic-dep
(since I doubt other tests will be added in this module)
test class: CyclicDependencyTest
-> FlagsCyclicDependencyTest
testn ame: basicCase
if (!isInitialized()) { | ||
return; | ||
} | ||
|
||
if (exporter == null) { | ||
exporter = builder.build(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we defer the creation of exporter
until isInitialized()
is true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
; so that isInitialized()
is only invoked when exporter
is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if I understood your intention 😅 I saw your second comment late, makes sense 👍
Doesn't the current change defer setting a value to exporter
until isInitialized() == true
by returning early already?
e.g.
if (exporter == null) {
if (!isInitialized()) {
return
}
exporter = builder.build();
}
logback/src/main/java/com/linecorp/armeria/common/logback/RequestContextExportingAppender.java
Outdated
Show resolved
Hide resolved
logback/src/main/java/com/linecorp/armeria/common/logback/RequestContextExportingAppender.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @jrhee17!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with the new changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this, @jrhee17!
Please update the PR description before merging. |
Oops 😅 Updated the |
Motivation:
A cyclic dependency can be introduced while
RequestContextStorageProvider
is being initialized.A possible scenario is as follows:
Given that a user defined
RCEA
and enabledFlags
logging:Flags#requestContextStorageProvider
Flags#requestContextStorageProvider
is fully initialized, a log is appendedarmeria/core/src/main/java/com/linecorp/armeria/common/Flags.java
Line 1392 in 6585634
RequestContextExportingAppender#append
is invoked, which eventually callsarmeria/core/src/main/java/com/linecorp/armeria/common/logging/RequestContextExporter.java
Line 204 in 6585634
RequestContextUtil
, which again callsFlags#requestContextStorageProvider
.null
is returned from this call which results in an error.armeria/core/src/main/java/com/linecorp/armeria/internal/common/RequestContextUtil.java
Lines 65 to 70 in 6585634
Modifications:
FlagsLoaded
class, which contains a static variableloaded
representing whetherFlags
has been completely loaded.Flags
which setsFlagsLoaded#loaded
totrue
viaFlagsLoaded#set
.FlagsLoaded#get
fromRequestContextExportingAppender
and don't proceed with the appender if not readyResult:
Flags
.