Infinite recursion in Keyword.intern leads to stack overflow

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.

Environment

None

Activity

Show:

import September 29, 2010 at 3:30 AM

Comment made by: importer

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

Branch: master

import September 29, 2010 at 3:30 AM

Comment made by: importer

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.

import September 29, 2010 at 3:30 AM

Comment made by: importer

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

import September 29, 2010 at 3:30 AM

Completed

Details

Assignee

Reporter

Fix versions

Created September 29, 2010 at 1:14 AM
Updated September 29, 2010 at 3:30 AM
Resolved September 29, 2010 at 3:30 AM