-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"error: integer out of range for 'L' format code" due to timeout=0 #48
Comments
Hi @hheimbuerger I was checking memcached docs and they don't say anything about keys that never expire, the best way to do this would be add |
@jaysonsantos So are you saying the comment in the Django source code ("To achieve this in memcache backends, a negative timeout must be passed.") is wrong and we should open a ticket with Django? I don't really understand your comment on changing it to Also, I don't think the original intention here was ever to explicitly say something about the timeout. The timeout 'just happens to come out of 0' by sheer coincidence and rounding errors. |
As a temporary workaround, I'm now overwriting
to
to prevent the @gmcquillan: Allow me to mention you here, because you appear to be the core maintainer of django-brake. Please let me know if you think this is a django-brake issue and I can move the issue there. I'm still unclear in which of the three libraries this should be fixed. I'm a bit surprised that I'm the only (or at least first) one experiencing this. I thought I'm pretty much using all three libraries in out-of-the-box configuration. |
1 - No, normally what libs like pylibc do is sending |
Could you try your previous code with this commit [1]? |
@jaysonsantos The "never expire" was confusing, I take that back. What I meant was "be kept around for as long as memcached is willing to hold on to it". Reading your commit, it looks to me like that's what's going to happen when django-brake passes down Are you willing to elaborate a bit more on the intentions and consequences your change has? |
@hheimbuerger which version of python, django, and django-brake are you using? |
@hheimbuerger I just mimicked pylibmc's behavior which is not wrong, I didn't see that coming before. |
@gmcquillan I'm using Python 2.7.11 (on Heroku's Cedar platform, i.e. Linux), django 1.8.12 and django-brake 1.5.2. Thanks for taking a look, guys! |
The value being passed to Django's cache backend is an int. It looks like it's being coerced to a Long before reaching bmemcache's protocol._set_and_replace function. I'd look there. |
@gmcquillan More specifically, the value being passed in by django-brake is not just an int, but it can be
Now when Unsurprisingly, packing I think you're right that this isn't really django-brake's fault. After all, |
Are you defining your periods in units smaller than a second? How would the timeout be getting set to 0 with django-brake? |
@gmcquillan I'm not quite following. Let's say
That's how the timeout is set to 0 by django-brake. It happens in the last second before |
@hheimbuerger I grok it now, thanks! However, 0 should mean that the value is not cached. -1, or None is cached forever.
We could certainly add a configuration value for making sure that this case is never hit. However, if the cache backend is well behaved, then it should be a noop, right? |
@gmcquillan Well, that was my concern about the change @jaysonsantos just made in c399163. It looked to me this will turn But reading it again now, I might be wrong. I'm still a bit confused about the where in the different layers across these three libraries things are happening and what I'm looking at. Update: Nope, I still think a |
What's the status of this issue? I still think your interpretation of |
Did you check what happens to pylibmc? My idea is to have the same behavior, and if I am not wrong it will be the max time - (abs(value)), and also on memcached there is no concept of infinity. |
I was curious about the official Django stance on this, and it looks like django/django@89955cc#diff-d603fa6afef1a44825847ccd4e9683a6R51 Henrik, If you're having a verified problem where the TTL is set to 0 (and the TTL Cheers, On Fri, Aug 19, 2016 at 8:40 AM, Jayson Reis [email protected]
|
That's an interesting change you found there in Django! That's for 1.10, correct? I'm still in the process of upgrading from 1.8 to 1.9... I'll have to think about that, I'm still pretty confused. Or debug through the whole stack, but that's not so easy for me to understand, too. Are you convinced that your current solution is working correctly with Django 1.8–1.10 and are you planning to release it to PyPI soon? |
Yeah, it's from the first instance I could find of the Django cache system I've only tested it through Django 1.8.2. On Fri, Aug 19, 2016 at 10:28 AM, Henrik Heimbuerger <
|
I found something clarifying, memcached/memcached#142 (comment) on the ASCII protocol this is what happens
But in the binary, there is no negative ttl, the right thing to do is to mimic this behavior. |
I'm using
django-bmemcached
andpython-binary-memcached
withdjango-brake
for rate limiting.Occasionally, I'm getting the following exception:
It turns out that the problem is
django-bmemcached
passing a value of-1
as the argumenttimeout
topython-binary-memcached
. The latter tries to pack this as anL
(unsigned long) into the struct, which of course fails for-1
.The
-1
comes from the following code inBaseMemcachedCache.get_backend_timeout()
:The code before that indicates that it occures when an entry is set the moment it expires:
According to the docs, a timeout of 0 for cache.set() is valid and won't cache the value. However, that's apparently not how
python-binary-memcached
works.Here I get a bit lost, just starting to use these libraries for the first time. I'm already pretty confused which code comes from which library. Can you help me out?
The text was updated successfully, but these errors were encountered: