Skip to content

Commit 74a9e38

Browse files
committed
Avoid infinite loop during session garbage collection. The GarbageCollection#scan method was not properly using the last_item parameter. This causes the #scan to repeatedly rescan the same set of DDB items instead of advancing through the items in the table. If all / many sessions were expired the gc would seem to work since gc deletes old sessions; however, for a real live system, the gc will appear to hang.
1 parent c849960 commit 74a9e38

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/aws/session_store/dynamo_db/garbage_collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def eliminate_unwanted_sessions(config, last_key = nil)
5959
# @api private
6060
def scan(config, last_item = nil)
6161
options = scan_opts(config)
62-
options.merge(start_key(last_item)) if last_item
62+
options = options.merge(start_key(last_item)) if last_item
6363
config.dynamo_db_client.scan(options)
6464
end
6565

spec/aws/session_store/dynamo_db/garbage_collection_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ def collect_garbage
111111

112112
it "gets scan results then returns last evaluated key and resumes scanning" do
113113
dynamo_db_client.should_receive(:scan).
114-
exactly(2).times.and_return(scan_resp2, scan_resp3)
114+
exactly(1).times.and_return(scan_resp2)
115+
dynamo_db_client.should_receive(:scan).
116+
exactly(1).times.with(hash_including({:exclusive_start_key => scan_resp2.last_evaluated_key})).
117+
and_return(scan_resp3)
115118
dynamo_db_client.should_receive(:batch_write_item).
116119
exactly(3).times.and_return(write_resp1)
117120
collect_garbage

0 commit comments

Comments
 (0)