AnsweredAssumed Answered

Bug: Too many open files after enabling Audit

Question asked by dnc on Sep 23, 2008
Latest reply on Oct 16, 2008 by andy
Hi,

I'm getting an error (too many open files) after enabling Audit in Alfresco Labs 3b.

To solve this problem I closed streams in method getAuditConfig() in HibernateAuditDAO.java

private AuditConfig getAuditConfig(final AuditState auditInfo)
    {

        AuditConfig auditConfig;
        auditConfig = queryLatestConfig(getSession());
        if (auditConfig == null)
        {
            auditConfig = createNewAuditConfigImpl(auditInfo);
        }
        else
        {

            InputStream current = new BufferedInputStream(auditInfo.getAuditConfiguration().getInputStream());
            ContentReader reader = contentStore.getReader(auditConfig.getConfigURL());
            reader.setMimetype(MimetypeMap.MIMETYPE_XML);
            reader.setEncoding("UTF-8");
            InputStream last = new BufferedInputStream(reader.getContentInputStream());
            int currentValue = -2;
            int lastValue = -2;
            try
            {
                while ((currentValue != -1) && (lastValue != -1) && (currentValue == lastValue))
                {
                    currentValue = current.read();
                    lastValue = last.read();

                }
            }
            catch (IOException e)
            {
                throw new AlfrescoRuntimeException("Failed to read and validate current audit configuration against the last", e);
            } finally {

                try {
                    current.close();
                    last.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (currentValue != lastValue)
            {
                // Files are different - require a new entry
                auditConfig = createNewAuditConfigImpl(auditInfo);
            }
            else
            {
                // No change
            }
        }

        return auditConfig;

    }

Outcomes