allegro / allegro/bigcache

Set failure even when there is enough memory left and size of entry is acceptable

Open
#214 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
8.2k
Forks
614
Avg merge
5d 12h
Merged PRs (30d)
1

Description

**What is the issue you are having?**
Set failing with `entry is bigger than max shard size`(2MB) even when there is enough memory left and size of entry is acceptable (38 kb)

**What is BigCache doing that it shouldn't?**
[Error in question](https://github.com/allegro/bigcache/blob/master/shard.go#L147)

Reason [removeOldestEntry](https://github.com/allegro/bigcache/blob/master/shard.go#L145) returned an error

Which was in-turn returned by [Pop](https://github.com/allegro/bigcache/blob/master/shard.go#L292)

[Pop](https://github.com/allegro/bigcache/blob/master/queue/bytes_queue.go#L159) will only return an error if `peek` fails

[Peek](https://github.com/allegro/bigcache/blob/master/queue/bytes_queue.go#L229) `can` return an error if the [queue is empty](https://github.com/allegro/bigcache/blob/master/queue/bytes_queue.go#L215)

`entry is bigger than max shard size` is not the correct error

**Minimal, Complete, and Verifiable Example**
Not able to reproduce it
```
config := &bigcache.Config{
LifeWindow: 2 * time.Hour,
CleanWindow: 1 * time.Second,
HardMaxCacheSize: 1024 * 2,
Shards: 1024,
}
```
But was reading the code and thought this could be one of the reason

When asking a question about a problem caused by your code, you will get much better answers if you provide code we can use to reproduce the problem. That code should be...

* ...Minimal – Use as little code as possible that still produces the same problem
* ...Complete – Provide all parts needed to reproduce the problem
* ...Verifiable – Test the code you're about to provide to make sure it reproduces the problem

For more information on how to provide an MCVE, please see the [Stack Overflow documentation](https://stackoverflow.com/help/mcve).

**Environment:**
- Version (git sha or release):
- OS (e.g. from `/etc/os-release` or winver.exe):
- go version:

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.