Clojure

Infinite recursion in Keyword.intern leads to stack overflow

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.3
  • Component/s: None
  • 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.

Activity

Hide
Assembla Importer added a comment -

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

Show
Assembla Importer added a comment - tomfaulhaber said: [file:a1Rf2-YY0r37R9eJe5cbLA]: bug fix
Hide
Assembla Importer added a comment -

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.

Show
Assembla Importer added a comment - 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.
Hide
Assembla Importer added a comment -

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

Branch: master

Show
Assembla Importer added a comment - richhickey said: (In [[r:167a73857a746e8dbeeb6d9ea8f99083aca7dc69]]) don't rely on softref queue, explicitly remove dead entry when found, fixes #444 Branch: master

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: