Giter Site home page Giter Site logo

Comments (5)

maggie44 avatar maggie44 commented on August 14, 2024 2

Thanks, hadn't spotted that.

Would have to think about it, I understand the @mgaffney's point. Adding a context would allow some control over the goroutine without it being an official method of the cache, but does feel like another workaround. Maybe there is a need for a workaround though, leaking goroutines isn't ideal.

At least with a context or the Close() we have some control over the issue. An issue from closing without properly handling the other functions calling the cache is a user error in implementation of the cache that can be rectified, or shouldn't occur in the first place if implemented per the documentation. Whereas a leaking goroutine is a code error in the library rather than a user error and one that can't be fixed by the user or worked around.

from golang-lru.

paskal avatar paskal commented on August 14, 2024 1

Please see #116 (comment) for the reasons I removed it, it was a requirement for merging as I understood it.

from golang-lru.

steebchen avatar steebchen commented on August 14, 2024 1

It would be great to have this, as running code with the -race detector currently fails due to this issue. I think it would be better to add a .Close() method to let the user call that when they are done (opposed to runtime.SetFinalizer as in the linked PR).

from golang-lru.

Super-long avatar Super-long commented on August 14, 2024

I'd like to add this for expirable-lru, but I don't know why the code is commented out here, and there's no mention of the reason in the commit message https://github.com/hashicorp/golang-lru/blob/main/expirable/expirable_lru.go#L277

from golang-lru.

maggie44 avatar maggie44 commented on August 14, 2024

I have come here with the same issue. It seems it was implemented in #116 by @paskal, but can't understand why the close option was removed.

expirable.NewLRU should probably receive a context so we can have control over that goroutine that is started as a replacement to .Close if it is going to be removed.

This has come up because all my tests automatically check for leaking goroutines by ensuring the number of goroutines at the beginning of the test is the same as it is at the end, and without being able to call a cancel() on a context passed to the LRU goroutine the tests will keep failing.

from golang-lru.

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.