sonatype/nexus — pull request #298 by mcculls (2012-02-12 23:50:31+00:00)
Title: NXCM-3892: avoid holding onto mdItem lock for longer than necessary

I think there's a potential deadlock in the M2Repository.doRetrieveItem method - at the top of this method a request for maven-metadata.xml.sha1 may be redirected to a request for the maven-metadata.xml, ie. sha1 locked before mdItem. Later on in the same method the mdItem stream is opened (content wrapped by ReadLockingContentLocator) and then the maven-metadata.xml.sha1 request is handled, with the mdItem stream only closed at the end. Because ReadLockingContentLocator only unlocks the item on the close this can lead to mdItem locked before sha1. I believe this inverse locking could lead to a deadlock.

Solution is to unlock the mdItem as soon as we can, before the call to fetch the maven-metadata.xml.sha1.