<< Back to previous view

[CLJ-444] Infinite recursion in Keyword.intern leads to stack overflow Created: 28/Sep/10  Updated: 28/Sep/10  Resolved: 28/Sep/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: Release 1.3

Type: Defect
Reporter: Anonymous Assignee: Rich Hickey
Resolution: Completed Votes: 0
Labels: None


 Description   

Keyword.intern keeps a table of SoftReferences to keywords, always preferring the existing one to making a new one. However, if the SoftReference has been pulled, the code tries to recurse as its way of "trying again."

Unfortunately, the way the logic is written, the code will work exactly the same way the second time around (and the third... it's turtles all the way down the stack) and eventually have a stack overflow.

I found this in a long running web service that was using XML RPC and then "keywordizing" the keys of the result maps. Within an hour or so, it would blow up on this. From my read of the code, there is no work around once you're in this state since the expired reference is stuck in the keyword table.

Patch coming momentarily.



 Comments   
Comment by Assembla Importer [ 28/Sep/10 9:30 PM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/444
Attachments:
keyword-intern.diff - https://www.assembla.com/spaces/clojure/documents/a1Rf2-YY0r37R9eJe5cbLA/download/a1Rf2-YY0r37R9eJe5cbLA

Comment by Assembla Importer [ 28/Sep/10 9:30 PM ]

tomfaulhaber said: [file:a1Rf2-YY0r37R9eJe5cbLA]: bug fix

Comment by Assembla Importer [ 28/Sep/10 9:30 PM ]

richhickey said: I don't think this analysis or patch is quite right.

The Util.clearCache call at the top of intern should delete the dead entry. I guess there can be a window in which the softreference hasn't yet been enqueued, if it has any extent you could spin and see your stack overflow.

But slamming in a new entry without the putIfAbsent logic risks an alias (two keywords with the same name) in a race condition.

Better to explicitly remove the entry (not waiting on the softref queue) and recur.

I'll fix.

Comment by Assembla Importer [ 28/Sep/10 9:30 PM ]

richhickey said: (In [[r:167a73857a746e8dbeeb6d9ea8f99083aca7dc69]]) don't rely on softref queue, explicitly remove dead entry when found, fixes #444

Branch: master

Generated at Mon Sep 22 21:32:35 CDT 2014 using JIRA 4.4#649-r158309.