Coder Social home page Coder Social logo

Comments (13)

swankjesse avatar swankjesse commented on July 24, 2024

Double checked locking should be fine. Unfortunately locking is what makes singleton scoping difficult. We have two bad choices:

  • Use a shared lock, and reduce concurrency when creating objects
  • Use independent locks and risk deadlock

I prefer the shared lock. The fix for this issue is to create that lock (probably just a new Object()) and to change singleton scope to use it. Double checked locking is fine; if checkstyle complains then we should silence checkstyle.

from dagger.

cgruber avatar cgruber commented on July 24, 2024

Do we necessarily have a deadlock if we signal whether a binding is requested for member or constructor injection, separate the flows for members injection and constructor injection, so construction can happen before members injection (of anything un-injected in the current transitive closure of the requested object), and explicitly disallow any cyclic reference among constructors?

I think we can do better than a global lock if we are willing to keep some constraints in place.

from dagger.

swankjesse avatar swankjesse commented on July 24, 2024

After thinking this over some, I think we aren't at risk of deadlock because we don't permit circular dependencies. So per-singleton locks suffice.

(That said, we also don't always statically check that no circular dependencies exist, so an application could still deadlock. But such an application would fail if dagger-compiler has validated it.)

from dagger.

cgruber avatar cgruber commented on July 24, 2024

I have a circular dependency analysis change I intend to put in shortly
into the full graph processor. Some point in Feb, this should be in if I
can get this internal crap done fast. (Hoping to finish this stuff this
week, or mid-next at the latest)

from dagger.

jameswald avatar jameswald commented on July 24, 2024

That's interesting, I'm pretty sure I was able to create a circular dependency which did pass the dagger-compiler. It generated a dot file with this graph:

this graph.

That obviously resulted in a stack overflow at runtime. If this isn't supposed to happen I can reproduce it tonight and try to fix it. The gist of it is that I injected the service into the application via an @Inject constructor, and in turn, the service injected the application via a @Module provider.

from dagger.

swankjesse avatar swankjesse commented on July 24, 2024

@cgruber what's your change do? ProblemDetector already tries to do this.

from dagger.

cgruber avatar cgruber commented on July 24, 2024

Hmm. I just walked the dependency graph passing in a stack of the
current path from the root, blowing up if the current node appeared in
the stack. Really simple.

from dagger.

swankjesse avatar swankjesse commented on July 24, 2024

Yeah, that's what ProblemDetector does.

from dagger.

cgruber avatar cgruber commented on July 24, 2024

Whoops. Then why aren't we failing at compile-time now… are we just
not applying it in full graph processor?

from dagger.

swankjesse avatar swankjesse commented on July 24, 2024

Nope, we aren't doing that yet. We should! It would just require a call to ObjectGraph.validate().

from dagger.

cgruber avatar cgruber commented on July 24, 2024
<facepalm/> 

from dagger.

cgruber avatar cgruber commented on July 24, 2024

The cycle-detection issue is fixed in #163. The singleton concurrency protection still needs to happen.

from dagger.

JakeWharton avatar JakeWharton commented on July 24, 2024

Whoops. Apparently this isn't fully done just yet.

from dagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.