<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Infinite loop in NX_ACCESS_ALLOWED in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318753#M5754</link>
    <description>&lt;P&gt;[NXP-18489](https&lt;/P&gt;</description>
    <pubDate>Sat, 28 Nov 2015 16:59:37 GMT</pubDate>
    <dc:creator>Florent_Guillau</dc:creator>
    <dc:date>2015-11-28T16:59:37Z</dc:date>
    <item>
      <title>Infinite loop in NX_ACCESS_ALLOWED</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318751#M5752</link>
      <description>&lt;P&gt;In our Nuxeo, we experimented a severe bug on the NX_ACCESS_ALLOWED function.
Looking closer, we saw that one of our document :&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;has no parentid + has a versionableid =&amp;gt; in the while loop first iteration, newid and curid are set to versionableid&lt;/LI&gt;
&lt;LI&gt;on the next iteration, no line is found corresponding to this versionableid : &lt;CODE&gt;SELECT parentid INTO newid FROM hierarchy WHERE hierarchy.id = curid;&lt;/CODE&gt; returns and does nothing. newid and curid remains the same, resulting in a infinite loop.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;May be our data are corrupted, but I cannot see any foreign key constraint on the versionableid columns in the database ?&lt;/P&gt;
&lt;P&gt;We applied the following patch (SET newid = NULL) to avoid the infinite loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;WHILE curid IS NOT NULL DO
  BEGIN
    ...	  
  END;
  -- OUR PATCH HERE
  SET newid = NULL;
  SELECT parentid INTO newid FROM hierarchy WHERE hierarchy.id = curid;
  IF first AND newid IS NULL THEN
    SELECT versionableid INTO newid FROM versions WHERE versions.id = curid;
  END IF;
  SET first = FALSE;
  SET curid = newid;
END WHILE;
RETURN FALSE; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It seems that everytime we restart our nuxeo, our patch is overriden by the application.
Can we do something about it?&lt;/P&gt;
&lt;P&gt;Moreover, I think that you may gain in performance by avoiding the cursor in the fisrt part of the function.
Something like this should perform the same task:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;SELECT `grant` INTO gr FROM `acls`
  WHERE `acls`.`id` = curid 
  AND LOCATE(CONCAT('|',user,'|'), allusers) &amp;lt;&amp;gt; 0 
  AND LOCATE(CONCAT('|',permission,'|'), allperms) &amp;lt;&amp;gt; 0
  ORDER BY `pos`
  LIMIT 1; 
IF gr IS NOT NULL THEN
	RETURN gr;
END IF;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks for your help,
Best regards,&lt;/P&gt;
&lt;P&gt;Xavier Pallot&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 13:36:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318751#M5752</guid>
      <dc:creator>Xavier_Pallot</dc:creator>
      <dc:date>2015-11-23T13:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite loop in NX_ACCESS_ALLOWED</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318752#M5753</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Thanks for the report.&lt;/P&gt;
&lt;P&gt;A version whose base document is deleted while there are still proxies pointing to it will have a &lt;CODE&gt;versionableid&lt;/CODE&gt; and no &lt;CODE&gt;parentid&lt;/CODE&gt; so it's a legitimate case. That's also why there is no foreign key constraint on &lt;CODE&gt;versionableid&lt;/CODE&gt;. I'm very surprised that this case was not reported before or covered by tests. I'll work on this in the coming days, &lt;A href="https://jira.nuxeo.com/browse/NXP-18489"&gt;NXP-18489&lt;/A&gt; has been opened to track this, you can follow this ticket for updates.&lt;/P&gt;
&lt;P&gt;Your patch looks good. But on startup Nuxeo by default re-writes all stored procedures in case they changed during upgrades, which is obviously a problem in this case. You could either patch the nuxeo-core-storage-sql JAR (file mysql.sql.txt contains the definition of the function), or disable the updates on startup using &lt;CODE&gt;nuxeo.vcs.noddl=true&lt;/CODE&gt; in nuxeo.conf.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 13:57:49 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318752#M5753</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2015-11-24T13:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite loop in NX_ACCESS_ALLOWED</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318753#M5754</link>
      <description>&lt;P&gt;[NXP-18489](https&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2015 16:59:37 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/infinite-loop-in-nx-access-allowed/m-p/318753#M5754</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2015-11-28T16:59:37Z</dc:date>
    </item>
  </channel>
</rss>

