<!-- 
RSS generated by JIRA (4.4#649-r158309) at Wed May 22 08:51:33 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/JDBC-11/JDBC-11.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[JDBC-11] Transaction not rolled back on Throwable exception</title>
                <link>http://dev.clojure.org/jira/browse/JDBC-11</link>
                <project id="10021" key="JDBC">java.jdbc</project>
                        <description>&lt;p&gt;(transaction&lt;br/&gt;
  (insert-values .....)&lt;br/&gt;
  (throw (Throwable. &quot;baaaaad&quot;)))&lt;/p&gt;

&lt;p&gt;Reported by Sebasti&#225;n Galkin on github.&lt;/p&gt;

&lt;p&gt;Transactions rollback on Exception but not Throwable.&lt;/p&gt;</description>
                <environment></environment>
            <key id="14479">JDBC-11</key>
            <summary>Transaction not rolled back on Throwable exception</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="3" iconUrl="http://dev.clojure.org/jira/images/icons/priority_major.gif">Major</priority>
                    <status id="5" iconUrl="http://dev.clojure.org/jira/images/icons/status_resolved.gif">Resolved</status>
                    <resolution id="1">Completed</resolution>
                                <assignee username="seancorfield">Sean Corfield</assignee>
                                <reporter username="seancorfield">Sean Corfield</reporter>
                        <labels>
                    </labels>
                <created>Sun, 3 Jul 2011 21:54:06 -0500</created>
                <updated>Sun, 17 Jul 2011 03:29:00 -0500</updated>
                    <resolved>Sun, 17 Jul 2011 03:28:58 -0500</resolved>
                                                                    <due></due>
                    <votes>1</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="26548" author="paraseba" created="Sun, 3 Jul 2011 23:07:55 -0500"  >&lt;p&gt;I think the correct behavior would be to call rollback on the transaction and not just not calling commit? The user will expect at the end of the transaction block one of commit or rollback to be called.&lt;/p&gt;

&lt;p&gt;I was thinking about how to test this. How do you feel about a mock Connection object, where we can check if commit and/or rollback have been called as part of the test?&lt;/p&gt;

&lt;p&gt;The same mechanism could be used to test other features.&lt;/p&gt;</comment>
                    <comment id="26549" author="paraseba" created="Mon, 4 Jul 2011 00:23:36 -0500"  >&lt;p&gt;I was thinking in something like the attached for testing the issue (and other functionality).&lt;br/&gt;
It needs several improvements, but it&apos;s enough to get the idea.&lt;br/&gt;
What do you think?&lt;/p&gt;</comment>
                    <comment id="26550" author="seancorfield" created="Mon, 4 Jul 2011 00:27:06 -0500"  >&lt;p&gt;FYI, here&apos;s the IRC discussion about this, for the record:&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;5:11pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
In clojure.java.jdbc there is a transaction function, which is supposed to rollback if the passed body throws an exception, but it only does that in case of an Exception, not any Throwable. What&apos;s the rationale behind this?&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:11pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
I&apos;d want my transaction rolledback in case of any errors&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:12pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
seancorfield: maybe you can explain me this?&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:53pm&amp;#93;&lt;/span&gt; &amp;lt;amalloy&amp;gt;&lt;br/&gt;
paraseba: catching Errors is generally a bad practice. i&apos;m not saying it&apos;s wrong all the time, but Errors are often unrecoverable anyway&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:53pm&amp;#93;&lt;/span&gt; &amp;lt;amalloy&amp;gt;&lt;br/&gt;
eg, &quot;You ran out of heap space! I can&apos;t even allocate memory to throw an exception!&quot;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:54pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
but, even in the worst conditions, shouldn&apos;t we try to rollback the transaction? is not better that commiting in this unexpected error condition?&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:55pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
we can then rethrow the Throwable, after trying to rollback&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:55pm&amp;#93;&lt;/span&gt; &amp;lt;lucian&amp;gt;&lt;br/&gt;
paraseba: i don&apos;t think the db will commit if it gives you an error&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:55pm&amp;#93;&lt;/span&gt; &amp;lt;lucian&amp;gt;&lt;br/&gt;
and as amalloy, errors like OOM are best solved with exit()&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:55pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
lucian: it will ... jdbc is catching Exception and rolling back in that case .... but it commits in a finally&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:56pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
so, if you have an Error thrown, it will commit&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:56pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
I guess that&apos;s more surprising than a rollback&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:57pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
the logic is .... (try do-your-thing (catch Exception roll-back) (finally commit))&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:57pm&amp;#93;&lt;/span&gt; &amp;lt;lucian&amp;gt;&lt;br/&gt;
paraseba: well, then maybe you don&apos;t want to commit in finally?&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:57pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
I don&apos;t, not if I got an Error&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:58pm&amp;#93;&lt;/span&gt; &amp;lt;amalloy&amp;gt;&lt;br/&gt;
lucian: i think he&apos;s upset that a library he&apos;s using is committing on error&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:59pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
amalloy: I can solve it easily by wrapping my operations in a catch Throwable -&amp;gt; rollback -&amp;gt; rethrow, but I think it&apos;s not the right behavior for the library&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;5:59pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
I would expect a commit only if the block ended without any kind of exceptions or errors. don&apos;t you agree ?&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;6:01pm&amp;#93;&lt;/span&gt; &amp;lt;amalloy&amp;gt;&lt;br/&gt;
paraseba: meh. all kinds of weird stuff can happen if an Error occurs; i wouldn&apos;t be entirely certain that an attempt to &quot;recover&quot; makes things worse due to some weird program state caused by the Error. i mean, my completely-unresearched opinion is that catching Throwable would be better, but you can&apos;t really rely for your program&apos;s correctness on anything that happens after an Error&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;6:02pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
but, we are forcing a commit after an Error&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;6:04pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
the usual logic should be .... (do do-your-thing  (commit))  if do-your-thing throws anything ... no commit is done. Puting a commit in a finally enforces the commit, even after Errors&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;6:06pm&amp;#93;&lt;/span&gt; &amp;lt;amalloy&amp;gt;&lt;br/&gt;
yeah, i think i agree&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;6:08pm&amp;#93;&lt;/span&gt; &amp;lt;paraseba&amp;gt;&lt;br/&gt;
amalloy: ok, I&apos;ll report an issue, thanks&lt;/p&gt;</comment>
                    <comment id="26561" author="paraseba" created="Sat, 9 Jul 2011 14:36:30 -0500"  >&lt;p&gt;It&apos;s important to realize that there are 2 problems here.&lt;/p&gt;

&lt;p&gt;a.- Transaction not rolled back on Throwable&lt;br/&gt;
b.- The original Exception is &quot;swallowed&quot; and a new, different one is thrown&lt;/p&gt;

&lt;p&gt;I think both are equally serious.&lt;/p&gt;</comment>
                    <comment id="26563" author="seancorfield" created="Sat, 9 Jul 2011 15:57:59 -0500"  >&lt;p&gt;I agree Sebastian. I&apos;ve raised this issue for input from clojure-dev (looking for stylistic guidelines for contrib libraries) because I think both problems need to be fixed.&lt;/p&gt;

&lt;p&gt;My current leaning is toward supporting three paths:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;success: rollback transaction if user code sets rollback true, else commit&lt;/li&gt;
	&lt;li&gt;Exception: rollback transaction and rethrow (without wrapping)&lt;/li&gt;
	&lt;li&gt;Throwable: allow it to escape, take no action&lt;/li&gt;
&lt;/ul&gt;
</comment>
                    <comment id="26567" author="paraseba" created="Tue, 12 Jul 2011 11:05:15 -0500"  >&lt;p&gt;I&apos;m attaching a patch that fixes the problem without adding any tests.&lt;/p&gt;</comment>
                    <comment id="26578" author="seancorfield" created="Sun, 17 Jul 2011 03:28:59 -0500"  >&lt;p&gt;On success, commit unless rollback has been set (in which case rollback).&lt;br/&gt;
On Exception, rollback and rethrow as-is.&lt;br/&gt;
On Error (Throwable), allow it to escape.&lt;br/&gt;
In all cases, set rollback false and restore auto-commit setting.&lt;/p&gt;

&lt;p&gt;The only two changes here should be:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Exception is no longer wrapped when thrown (may break code that expected the wrapping?)&lt;/li&gt;
	&lt;li&gt;No commit attempted on Error (Throwable)&lt;/li&gt;
&lt;/ul&gt;
</comment>
                </comments>
                    <attachments>
                    <attachment id="10276" name="0001-Don-t-commit-transaction-in-case-of-exceptions.patch" size="1220" author="paraseba" created="Tue, 12 Jul 2011 11:05:15 -0500" />
                    <attachment id="10269" name="test-mechanism.patch" size="3767" author="paraseba" created="Mon, 4 Jul 2011 00:23:36 -0500" />
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                                                                            </customfields>
    </item>
</channel>
</rss>