Bugs: Browse | Submit New | Admin

[#13721] [PATCH] raw setting anything but a string can cause library to hang

Date:
2007-09-06 21:26
Priority:
3
Submitted By:
Elijah Miller (jqr)
Assigned To:
Mike Perham (mperham)
Category:
memcache-client
State:
Open
Summary:
[PATCH] raw setting anything but a string can cause library to hang

Detailed description
The offending line:

    command = "set #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n"

The problem is the length part of the set command is done on it's pre-string form and not after conversion even though
it will be converted to a string before being sent to the server.

For example:
  CACHE.set('test', 1, 1, true)

  value.size == 1.size == 4
  value.to_s.size == 1.to_s.size == 1

  => set test 0 1 4 1

The server ends up waiting for 3 more bytes that never come.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-09-08 04:34
Sender: Eric Hodel

Ok, I will consider it.
Date: 2007-09-08 04:18
Sender: Elijah Miller

Since to_s is called on value already, is there any harm in
calling it before the size call?

I think this behavior is preferable to never returning
memcache calls. If you still disagree then I think these
methods should an error on non string values.
Date: 2007-09-08 03:43
Sender: Eric Hodel

It is not broken.  Raw mode is for String values only.  Don't
supply non-string values when raw is true.

Attached Files:

Name Description Download
memcache-client_raw_fix.diff memcache-client raw fix Download

Changes:

Field Old Value Date By
assigned_todrbrain2009-03-31 00:03zenspider
status_idClosed2007-09-08 04:34drbrain
close_date2007-09-08 04:182007-09-08 04:18jqr
close_date2007-09-08 03:432007-09-08 03:43drbrain
resolution_idNone2007-09-08 03:43drbrain
status_idOpen2007-09-08 03:43drbrain
File Added2474: memcache-client_raw_fix.diff2007-09-06 21:26jqr