Skip to content

Commit

Permalink
brokers leak because of exception at broker.flush call
Browse files Browse the repository at this point in the history
  • Loading branch information
shabanovd committed Sep 23, 2013
1 parent c3a6502 commit cec7b17
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
71 changes: 48 additions & 23 deletions src/org/exist/dom/ElementImpl.java
Expand Up @@ -425,8 +425,13 @@ public Node appendChild(Node child) throws DOMException {
transact.abort(transaction);
throw new DOMException(DOMException.INVALID_STATE_ERR, e.getMessage());
} finally {
transact.close(transaction);
ownerDocument.getBrokerPool().release(broker);
if (broker != null) {
try {
transact.close(transaction);
} finally {
broker.release();
}
}
}
}

Expand Down Expand Up @@ -502,7 +507,8 @@ public void appendChildren(Txn transaction, NodeList nodes, int child) throws DO
} catch (final EXistException e) {
LOG.warn("Exception while appending child node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
}

Expand Down Expand Up @@ -658,7 +664,8 @@ private Node appendChild(Txn transaction, NodeId newNodeId, NodeImplRef last, No
} catch (final EXistException e) {
LOG.warn("Exception while appending node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return null;
}
Expand Down Expand Up @@ -737,7 +744,8 @@ public NamedNodeMap getAttributes() {
} catch (final EXistException e) {
LOG.warn("Exception while retrieving attributes: " + e.getMessage());
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
}
if (declaresNamespacePrefixes()) {
Expand Down Expand Up @@ -765,7 +773,8 @@ private AttrImpl findAttribute(String qname) {
} catch (final EXistException e) {
LOG.warn("Exception while retrieving attributes: " + e.getMessage());
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return null;
}
Expand Down Expand Up @@ -793,7 +802,8 @@ private AttrImpl findAttribute(QName qname) {
} catch (final EXistException e) {
LOG.warn("Exception while retrieving attributes: " + e.getMessage());
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return null;
}
Expand Down Expand Up @@ -866,7 +876,8 @@ public NodeList getChildNodes() {
} catch (final EXistException e) {
LOG.warn("Internal error while reading child nodes: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return childList;
}
Expand Down Expand Up @@ -908,7 +919,8 @@ public Node getFirstChild() {
} catch (final EXistException e) {
LOG.warn("Exception while retrieving child node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return null;
}
Expand Down Expand Up @@ -981,7 +993,8 @@ public String getNodeValue() /*throws DOMException*/ {
} catch (final EXistException e) {
LOG.warn("Exception while reading node value: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return "";
}
Expand Down Expand Up @@ -1180,8 +1193,13 @@ public Node insertBefore(Node newChild, Node refChild) throws DOMException {
transact.abort(transaction);
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
transact.close(transaction);
ownerDocument.getBrokerPool().release(broker);
if (broker != null) {
try {
transact.close(transaction);
} finally {
broker.release();
}
}
}
return null;
}
Expand Down Expand Up @@ -1233,7 +1251,8 @@ public void insertBefore(Txn transaction, NodeList nodes, Node refChild) throws
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
}

Expand Down Expand Up @@ -1276,7 +1295,8 @@ public void insertAfter(Txn transaction, NodeList nodes, Node refChild) throws D
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
}

Expand Down Expand Up @@ -1336,7 +1356,8 @@ public void update(Txn transaction, NodeList newContent) throws DOMException {
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
}

Expand Down Expand Up @@ -1406,7 +1427,8 @@ public StoredNode updateChild(Txn transaction, Node oldChild, Node newChild) thr
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return newNode;
}
Expand Down Expand Up @@ -1449,7 +1471,8 @@ public Node removeChild(Txn transaction, Node oldChild) throws DOMException {
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
return oldNode;
}
Expand Down Expand Up @@ -1504,14 +1527,15 @@ public void removeAppendAttributes(Txn transaction, NodeList removeList, NodeLis
setDirty(true);
}
attributes += appendList.getLength();

broker.updateNode(transaction, this, true);
broker.flush();

} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
if (broker != null) {
broker.updateNode(transaction, this, true);
broker.flush();
ownerDocument.getBrokerPool().release(broker);
}
if (broker != null)
broker.release();
}
}

Expand Down Expand Up @@ -1586,7 +1610,8 @@ public Node replaceChild(Txn transaction, Node newChild, Node oldChild) throws D
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
ownerDocument.getBrokerPool().release(broker);
if (broker != null)
broker.release();
}
//return oldChild; // method is spec'd to return the old child, even though that's probably useless in this case
return newNode; //returning the newNode is more sensible than returning the oldNode
Expand Down
4 changes: 4 additions & 0 deletions src/org/exist/storage/DBBroker.java
Expand Up @@ -826,4 +826,8 @@ public abstract EmbeddedXMLStreamReader newXMLStreamReader(NodeHandle node, bool
public abstract void backupToArchive(RawDataBackup backup) throws IOException, EXistException;

public abstract void readCollectionEntry(SubCollectionEntry entry);

public void release() {
pool.release(this);
}
}

0 comments on commit cec7b17

Please sign in to comment.