Building components in Future causes strange errors#918
Conversation
cfc8756 to
4eeb193
Compare
|
Trace log shows Surfaces of Config1, 2 objects are Surface.of[Object]. It looks like a bug of Surface.of[X]: |
|
A minimization is: Future{
Surface.of[Config1] // wrongly returns Surface.of[Object].
} |
|
A recent big change around Surface is #878. Let me check the cause. |
|
@takezoe The cause is the global execution context of the Future, which cannot find Config1 class. This might be caused by sbt's layered class loader. For example, if we use our own execution context, all tests will pass: //import scala.concurrent.ExecutionContext.Implicits.global
private val ex = Executors.newFixedThreadPool(1)
private implicit val context = ExecutionContext.fromExecutor(ex)
|
|
class loader hierarchy inside the test code (or using our own ExecutionContext): Class loader hierarchy within Future when using the global context: |
|
@takezoe This is a bug of sbt's layered classloader, which might be initializing Future's global context by using a non-application class loader. A workaround is adding this configuration: Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat |
|
Filed a bug ticket to sbt sbt/sbt#5410 |
|
@takezoe Although, it's a bug of sbt's layered class loader, we should define our own ExecutionContext when using Future like this: or using DI: |
|
I see. Thanks for investigation! |
|
Let me close this PR as we've found the root cause (sbt's class loader). |
|
#1014 might be a fix for this issue. |
Codecov Report
@@ Coverage Diff @@
## master #918 +/- ##
=======================================
Coverage 81.96% 81.96%
=======================================
Files 269 269
Lines 10118 10118
Branches 692 692
=======================================
Hits 8293 8293
Misses 1825 1825 Continue to review full report at Codecov.
|
|
After #1014, the error message has been changed like this: This error means, Config1 is loaded by different classloaders and two instances of Config1 has been generated. I'll add a note about a workaround for avoiding such an issue. |
612edab to
1eb78d0
Compare
This test fails as follows. I believe that it had been working at some points of the previous versions of Airframe.