Code Monkey home page Code Monkey logo

Comments (5)

elboulangero avatar elboulangero commented on June 5, 2024 1

I also bumped into this issue. It seems to be a bug with the LRU cache (mirrors/cache.go)

Mirrorbits uses an internal LRU cache in front of the Redis database: when it needs to request information about a file, it first queries the LRU cache, and if ever the result is in there, it doesn't query the database. Of course, it means that when file information are updated (ie. a scan returns, and updated values are committed to the database), entries in the LRU cache must be invalidated.

This part of the code is problematic:

// Notify subscribers of the new message
func (p *Pubsub) handleMessage(channel string, data []byte) {
p.extSubscribersLock.RLock()
defer p.extSubscribersLock.RUnlock()
listeners := p.extSubscribers[channel]
for _, listener := range listeners {
select {
case listener <- string(data):
default:
// Don't block if the listener is not available
// and drop the message.
}
}
}

The "listener" here is in fact the LRU cache, and the content of the message is a file path. When a scan returns, every file is updated in the database, generating a message in the channel for each file. So it means this function handleMessage is called many times, as many times as there's files in the repo, every time a scan returns.

However, as is clearly stated in the code snippet above: when the channel is full, mirrorbits doesn't wait for the listeners to consume messages in the channel. Instead it just drops the message. I did a quick test, and around 7% of the messages were dropped. If messages are dropped, the LRU cache is never notified that some files were updated, and so outdated entries are not discarded as they should.

I suppose that, for a busy instance, the issue can easily go unnoticed, as entries in the LRU cache will be evicted anyway (LRU = Least Recently Used). And if ever they are not evicted, the consequence is just that mirrorbits might redirect to fallback, instead of redirecting to valid mirrors.

But for a mirrorbits instance that doesn't receive much traffic, outdated entries can stay there forever, and the issue is very visible. As @zen-fu noted, a restart is enough to fix it (since the LRU cache doesn't survive a restart).


So the easy fix is just to make mirrorbits wait when the channel is full. I'm testing it, it seems to work so far.

from mirrorbits.

lazka avatar lazka commented on June 5, 2024

In general there is some problem with things getting cached and only "fixing themselves" after some minutes.

from mirrorbits.

zen-fu avatar zen-fu commented on June 5, 2024

We bumped into the same issue but after 12h the situation was still the same.

  • Triggering a mirrorbits refresh didn't make a difference.
  • Restarting the service fixed file sizes and hashes.

from mirrorbits.

elboulangero avatar elboulangero commented on June 5, 2024

This issue can be closed now

from mirrorbits.

lazka avatar lazka commented on June 5, 2024

Thanks!

from mirrorbits.

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.