Closed Bug 739697 Opened 12 years ago Closed 12 years ago

(NS_ERROR_FAILURE) [mozIStorageConnection.beginTransaction] Stack trace: resource:///components/nsFormHistory.js:253 < FormStore_remove()

Categories

(Toolkit :: Form Manager, defect)

13 Branch
defect
Not set
major

Tracking

()

RESOLVED FIXED
mozilla14
Tracking Status
firefox13 + fixed
firefox14 + fixed

People

(Reporter: joe, Assigned: MattN)

References

Details

(Whiteboard: [qa-])

Attachments

(2 files, 2 obsolete files)

Attached file error log
My Aurora profile has a continuous sync error, seemingly in the forms data engine. I've attached the error log.
Sounds like your profile is screwed…
Component: Firefox Sync: Backend → Form Manager
Product: Mozilla Services → Toolkit
QA Contact: sync-backend → form.manager
Summary: Constant sync error in Aurora → (NS_ERROR_FAILURE) [mozIStorageConnection.beginTransaction] Stack trace: resource:///components/nsFormHistory.js:253 < FormStore_remove()
Version: unspecified → 13 Branch
Does form history still work in forms and the search box?  Try adding, selecting, and deleting entries.
Yeah, I can operate on my form history just fine, it seems.
(In reply to Joe Drew (:JOEDREW!) from comment #3)
> Yeah, I can operate on my form history just fine, it seems.

Joe or other reporters, can you set browser.formfill.debug = true and then follow these steps:
1) Clear your error console
2) Go to a form with form history entries.
3) Type some text to get a list of entries.
4) Select an entry and delete it. See https://support.mozilla.org/en-US/kb/Form-autocomplete#w_deleting-individual-form-entries
5) Type some other text in the same field to overwrite the result cache.
6) Type the same text from #3 and see if the deleted result shows up.
7) Check the error console for warning or errors related to form history aka. Satchel and paste them here.
Possibly related to bug 725881 which added a moz_deleted_formhistory table.
(In reply to Matthew N. [:MattN] from comment #6)
> 7) Check the error console for warning or errors related to form history
> aka. Satchel and paste them here.

To be clear, they probably wont' be reported as "Errors" or "Warnings" in the console, they will mostly show as "Messages".
Mostly, there are no errors from that sequence of events. However, I got some seemingly sync-related errors afterwards:

FormHistory: entryExists for searchbar-history=arm branch instructions
FormHistory: entryExists: id=6871
FormHistory: entryExists for searchbar-history=eglInitialize
FormHistory: entryExists: id=6872
FormHistory: addEntry for searchbar-history=hyatt regency sf
FormHistory: Creating new statement for query: INSERT INTO moz_formhistory (fieldname, value, timesUsed, firstUsed, lastUsed, guid) VALUES (:fieldname, :value, :timesUsed, :firstUsed, :lastUsed, :guid)
FormHistory: removeEntry for firstName=Joe
FormHistory: removeEntry failed: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.beginTransaction]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: resource:///components/nsFormHistory.js :: <TOP_LEVEL> :: line 253"  data: no]

Sync then notices the failure and errors out.
I think this is because bug 725881 made more APIs use transactions and according to MDN[1], nested transactions are not supported: "The database engine does not support nested transactions, so attempting to start a transaction when one is already active will throw an exception."

It seems that the problem is that Sync is beginning a transaction for formhistory.sqlite[2] but then removeEntry begins its own transaction at nsFormHistory.js:253 since bug 725881 landed.

[1] https://developer.mozilla.org/en/Storage#Transactions
[2] https://mxr.mozilla.org/mozilla-central/source/services/sync/modules/engines/forms.js?rev=13a57f89f8cc&force=1#211
moveToDeletedTable is ifdeffed on only for Android, which is the only platform on which we use the deleted items table.

Perhaps the transaction handling for those newly transactional methods ought to be conditional also, or check dbConnection.transactionInProgress…
Depends on: 725881
This, unfortunately, has now progressed to my main profile! It appeared as I was in the middle of using Firefox.
(In reply to Joe Drew (:JOEDREW!) from comment #12)
> This, unfortunately, has now progressed to my main profile! It appeared as I
> was in the middle of using Firefox.

Yes, this will reliably affect any Firefox 13+ profile that attempts to sync a form history deletion. It's not going to be an intermittent thing.
Severity: normal → major
OS: Mac OS X → All
Hardware: x86 → All
I'll make a patch for #ifdef ANDROID now since bug 566746 is around the corner which will clean some of these problems up.
Assignee: nobody → mnoorenberghe+bmo
Status: NEW → ASSIGNED
#ifdef ANDROID for removeEntry and removeAllEntries

The transaction doesn't do us any good for removeEntry outside of Android anyways.
Attachment #612753 - Flags: review?(rnewman)
Attachment #612753 - Flags: review?(paul)
Comment on attachment 612753 [details] [diff] [review]
#ifdef ANDROID around transaction code which isn't necessary for non-android in the specific cases for Sync

Review of attachment 612753 [details] [diff] [review]:
-----------------------------------------------------------------

Call this a conditional review: it looks good to me if this is the approach zpao wants to take. I don't own this code.

(Note that your patch needs bug headers: https://developer.mozilla.org/en/Mercurial_FAQ#How_can_I_generate_a_patch_for_somebody_else_to_check-in_for_me.3F )

My opinion gently leans towards making this code more robust in general, rather than ifdeffing around the issue: that is, if it can't support nested transactions, make it aware of outstanding transactions and dynamically behave appropriately. Otherwise we're eventually going to hit exactly the same problem in some other calling code that doesn't expect a transaction to be started here. This should be fairly straightforward, and makes the module strictly more flexible.

zpao?
Attachment #612753 - Flags: review?(rnewman) → review+
Comment on attachment 612753 [details] [diff] [review]
#ifdef ANDROID around transaction code which isn't necessary for non-android in the specific cases for Sync

Review of attachment 612753 [details] [diff] [review]:
-----------------------------------------------------------------

I know you & dolske talked about just doing this, but I think Richard is right. It's just as easy to check connection.transactionInProgress at the beginning of these methods & just not dong any transaction work if true.

The end goal is to just get async form history done & in where this gets automagically handled, but we're not there yet.

(insert grumble about not exposing dbconnection to take away footguns)
Attachment #612753 - Flags: review?(paul) → review-
I put the access of transactionInProgress in the try block in case the connection is null.  Let me know if you prefer the declaration and assignment on the same line.

(In reply to Richard Newman [:rnewman] from comment #16)
> (Note that your patch needs bug headers:
> https://developer.mozilla.org/en/
> Mercurial_FAQ#How_can_I_generate_a_patch_for_somebody_else_to_check-
> in_for_me.3F )

I have commit access so don't use checkin-needed and there isn't an HG command that I know to export the patch with 8 lines of context while keeping 3 lines for MQ.  

> My opinion gently leans towards making this code more robust in general,
> rather than ifdeffing around the issue: that is, if it can't support nested
> transactions, make it aware of outstanding transactions and dynamically
> behave appropriately. Otherwise we're eventually going to hit exactly the
> same problem in some other calling code that doesn't expect a transaction to
> be started here. This should be fairly straightforward, and makes the module
> strictly more flexible.

Sure, but we will hopefully be able to get rid of external access to DBConnection once bug 566746 lands.
Attachment #612753 - Attachment is obsolete: true
Attachment #613006 - Flags: review?(paul)
(In reply to Matthew N. [:MattN] from comment #18)

> I have commit access so don't use checkin-needed …

It's nice when the patch that gets r+ is the same as the one that lands (e.g., for uplift approval), regardless of whether you're able to check it in yourself.

> and there isn't an HG
> command that I know to export the patch with 8 lines of context while
> keeping 3 lines for MQ.  

I use these:

[diff]
git = 1
unified = 8
showfunc = true

[defaults]
diff=-U8
qdiff=-U8
qnew=-U
qseries=-sv

You can replace the qdiff line with `qdiff=-U3`, which *should* (I haven't tested) make the patch file itself (the one we care about) contain 8 lines of context, but include only 3 lines when using qdiff -- or vice versa if that's what you care about. So long as you upload with 8!

Try it out and let me know how it goes!

> Sure, but we will hopefully be able to get rid of external access to
> DBConnection once bug 566746 lands.

I can't believe that bug's still going! :D

Making the forms API async doesn't eliminate the need for performance-aware callers to manually manage transactions. There is likely to still be work required to address that before Sync can avoid getting elbow-deep in database prodding.

(Sync adds form items fifty at a time, because it might be inserting three or four thousand, and sixty write transactions are way better than three thousand.)
(In reply to Richard Newman [:rnewman] from comment #19)
> [diff]
> git = 1
> unified = 8

From when I last tested, it's this `unified = 8` line above that is used for MQ and for export so you can't have one diff from the other.

> Making the forms API async doesn't eliminate the need for performance-aware
> callers to manually manage transactions. There is likely to still be work
> required to address that before Sync can avoid getting elbow-deep in
> database prodding.

Yeah, I realize that. It's not the async aspect of the bug, it's the new API which Sync requested.  If there is something more that is needed they can possibly be included in that bug.
Comment on attachment 613006 [details] [diff] [review]
v.2 check for existing transaction

(In reply to Matthew N. [:MattN] from comment #18)
> Created attachment 613006 [details] [diff] [review]
> v.2 check for existing transaction
> 
> I put the access of transactionInProgress in the try block in case the
> connection is null.  Let me know if you prefer the declaration and
> assignment on the same line.

If the connection is null/that can throw, then we're in trouble. transactionInProgress will be falsey after the try/catch/finally where we then would attempt to commit. We've made assumptions about the connection in the past so let's just move it out of the try block. If you think we need to handle that error separately (rethrow or whatever), then do what you think is appropriate before the try block.
Attachment #613006 - Flags: review?(paul)
(In reply to Paul O'Shannessy [:zpao] from comment #21)
> Comment on attachment 613006 [details] [diff] [review]
> v.2 check for existing transaction
> 
> (In reply to Matthew N. [:MattN] from comment #18)
> > Created attachment 613006 [details] [diff] [review]
> > v.2 check for existing transaction
> > 
> > I put the access of transactionInProgress in the try block in case the
> > connection is null.  Let me know if you prefer the declaration and
> > assignment on the same line.
> 
> If the connection is null/that can throw, then we're in trouble.
> transactionInProgress will be falsey after the try/catch/finally where we
> then would attempt to commit. (In reply to Paul O'Shannessy [:zpao] from comment #21)
> Comment on attachment 613006 [details] [diff] [review]
> v.2 check for existing transaction
> 
> (In reply to Matthew N. [:MattN] from comment #18)
> > Created attachment 613006 [details] [diff] [review]
> > v.2 check for existing transaction
> > 
> > I put the access of transactionInProgress in the try block in case the
> > connection is null.  Let me know if you prefer the declaration and
> > assignment on the same line.
> 
> If the connection is null/that can throw, then we're in trouble.
> transactionInProgress will be falsey after the try/catch/finally where we
> then would attempt to commit.

Actually, the catch block is rethrowing the exception in all of these cases so this isn't actually an issue from what I can tell.

I'm attaching a patch that does what you requested anyways since both options seem fine to me. Review whichever one you prefer.
Attachment #615615 - Flags: review?(paul)
(In reply to Matthew N. [:MattN] from comment #22)
> Actually, the catch block is rethrowing the exception in all of these cases
> so this isn't actually an issue from what I can tell.

Oh true. Not sure what I was thinking... either I missed the rethrow or I was thinking the commit was inside the finally block...
Comment on attachment 613006 [details] [diff] [review]
v.2 check for existing transaction

[Approval Request Comment]
Regression caused by (bug #): bug 725881
User impact if declined: User will see a persistent sync notification bar at the bottom of their browser if a form history entry was deleted and needs to sync.
Testing completed (on m-c, etc.): m-c
Risk to taking this patch (and alternatives if risky): Low risk of breaking form history deletion in a different way although we do have unit/mochitests for that.
String changes made by this patch: None
Attachment #613006 - Flags: approval-mozilla-central?
Attachment #613006 - Flags: approval-mozilla-aurora?
Comment on attachment 613006 [details] [diff] [review]
v.2 check for existing transaction

[Triage Comment]
Approving for central since this is something we'd want to track for release. We'll check back in a couple of days for aurora approval.
Attachment #613006 - Flags: approval-mozilla-central? → approval-mozilla-central+
Thanks.

https://hg.mozilla.org/integration/mozilla-inbound/rev/9d11d469890f
Flags: in-testsuite+
Target Milestone: --- → mozilla14
Attachment #615615 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/9d11d469890f
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Comment on attachment 613006 [details] [diff] [review]
v.2 check for existing transaction

Approving for Aurora 13 now that this has had a day of bake time on m-c.
Attachment #613006 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Can someone who was able to reproduce this bug please verify the fix in Firefox 13.0b3 and latest-mozilla-aurora?
Whiteboard: [qa-]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: