Skip to content
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

Fixes a SERVER_ERROR when value length is just under the max value length #272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mgetz
Copy link

@mgetz mgetz commented Sep 16, 2015

There is a small window of value size just under the max value size that causes a SERVER_ERROR. That window is the key length + the length of meta data stored with the key value pair. When the value size is over the max value length, the driver nicely throws an error back to the client without causing the SERVER_ERROR. This closes that small window that is left.

I hardcoded in the size of the metadata that I found on my system but I am not sure that is correct for all systems. The places where I found the meta data length mentioned cited a shorter length for most systems so hopefully this takes care of those systems as well with only a few bytes of unusable space.

@@ -913,7 +913,7 @@ Client.config = {
value = Utils.escapeValue(value);

length = Buffer.byteLength(value);
if (length > this.maxValue) {
if (length + fullkey.length + 71 > this.maxValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment explaining the logic behind this (and the magic constant that is 71) would be appreciated :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation I found said that 71 is the length of the metadata that memcache uses to store information about each key value pair. That may need to be adjusted or set as a system variable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to keep in mind is that memcache clients can also talk to Couchbase servers. I don't know what the limitations are there? In any case, I think a code comment or well chosen constant name would be nice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the tips. We use it with both memcached and couchbase ourselves. I will do a bit more research and tweak the code accordingly.
Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants