Bug 227771 - Return error for statement if the transaction it belongs to is rolled back
Summary: Return error for statement if the transaction it belongs to is rolled back
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sihui Liu
URL:
Keywords: InRadar
Depends on:
Blocks: 227887
  Show dependency treegraph
 
Reported: 2021-07-07 14:13 PDT by Sihui Liu
Modified: 2021-07-14 14:14 PDT (History)
3 users (show)

See Also:


Attachments
Patch (13.94 KB, patch)
2021-07-07 14:45 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (14.02 KB, patch)
2021-07-08 01:03 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (14.12 KB, patch)
2021-07-08 12:56 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (14.23 KB, patch)
2021-07-08 20:32 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (24.75 KB, patch)
2021-07-08 23:22 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (25.19 KB, patch)
2021-07-09 12:02 PDT, Sihui Liu
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (25.19 KB, patch)
2021-07-09 12:09 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (25.28 KB, patch)
2021-07-09 12:27 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (5.96 KB, patch)
2021-07-13 17:43 PDT, Sihui Liu
sihui_liu: review?
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sihui Liu 2021-07-07 14:13:49 PDT
...
Comment 1 Sihui Liu 2021-07-07 14:45:14 PDT
Created attachment 433080 [details]
Patch
Comment 2 Sihui Liu 2021-07-08 01:03:32 PDT
Created attachment 433125 [details]
Patch
Comment 3 Sihui Liu 2021-07-08 12:56:08 PDT
Created attachment 433156 [details]
Patch
Comment 4 Sihui Liu 2021-07-08 20:32:02 PDT
Created attachment 433196 [details]
Patch
Comment 5 Sihui Liu 2021-07-08 23:22:42 PDT
Created attachment 433200 [details]
Patch
Comment 6 Chris Dumez 2021-07-09 09:40:48 PDT
Comment on attachment 433200 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433200&action=review

I don't really understand the purpose of this patch and there is no test to show the usefulness either. Here are some random comments though.

> Source/WebCore/Modules/webdatabase/SQLTransaction.cpp:-209
> -        m_sqliteTransaction->stop();

Why is this no longer stopping the transaction? I am assuming it is not needed because the destructor already takes care of stopping the transaction? Either way, I think a comment in the changelog for this function would be helpful understand such changes.

> Source/WebCore/platform/sql/SQLiteDatabase.cpp:739
> +    return !m_writeTransactionInProgress || !m_writeTransactionInProgress->rolledBackBySQLite();

I don't understand this logic. So if `!m_writeTransactionInProgress` (meaning there is no write transaction in progress), then I have a valid transaction?

I would have expected:
return m_writeTransactionInProgress && !m_writeTransactionInProgress->rolledBackBySQLite();

Either there is a bug or at the very least, this code is confusing.

> Source/WebCore/platform/sql/SQLiteDatabase.h:163
> +    SQLiteTransaction* writeTransactionInProgress() const { return m_writeTransactionInProgress; }

Having a getter start with "write" seems a bit confusing to me.

> Source/WebCore/platform/sql/SQLiteDatabase.h:179
> +    SQLiteTransaction* m_writeTransactionInProgress { nullptr };

We store store raw pointers as data members anymore. This is a security bug waiting to happen. If you really need a pointer, it should probably be a WeakPtr.

> Source/WebCore/platform/sql/SQLiteTransaction.h:47
> +    bool rolledBackBySQLite() const;

How is this new name a progression? Seems to go against WebKit coding style that states we should use prefixes for booleans.
Comment 7 Chris Dumez 2021-07-09 09:42:15 PDT
Comment on attachment 433200 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433200&action=review

>> Source/WebCore/platform/sql/SQLiteDatabase.h:179
>> +    SQLiteTransaction* m_writeTransactionInProgress { nullptr };
> 
> We store store raw pointers as data members anymore. This is a security bug waiting to happen. If you really need a pointer, it should probably be a WeakPtr.

I meant: we avoid storing raw pointers as data members nowadays.
Comment 8 Sihui Liu 2021-07-09 11:36:21 PDT
(In reply to Chris Dumez from comment #6)
> Comment on attachment 433200 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=433200&action=review
> 
> I don't really understand the purpose of this patch and there is no test to
> show the usefulness either. Here are some random comments though.

For a explicit transaction, we usually begin the transaction, run some statements, and commit/abort the transaction. Currently we rely on the caller of SQLiteTransaction to track the state. If the caller fails to check the state, the statements may run as separate transactions . This patch aims to ensure the statements inside a write transaction are executed together. It does not handle read transactions as the consequences are not as bad if read statements are run separately.

This will help us to implement aborting all SQLiteTransactions synchronously on suspension: all subsequent statements in the same transaction scope will fail.

> 
> > Source/WebCore/Modules/webdatabase/SQLTransaction.cpp:-209
> > -        m_sqliteTransaction->stop();
> 
> Why is this no longer stopping the transaction? I am assuming it is not
> needed because the destructor already takes care of stopping the
> transaction? Either way, I think a comment in the changelog for this
> function would be helpful understand such changes.

Will add.

> 
> > Source/WebCore/platform/sql/SQLiteDatabase.cpp:739
> > +    return !m_writeTransactionInProgress || !m_writeTransactionInProgress->rolledBackBySQLite();
> 
> I don't understand this logic. So if `!m_writeTransactionInProgress`
> (meaning there is no write transaction in progress), then I have a valid
> transaction?
> 
> I would have expected:
> return m_writeTransactionInProgress &&
> !m_writeTransactionInProgress->rolledBackBySQLite();
> 
> Either there is a bug or at the very least, this code is confusing.

This is for checking in step(); the statement cannot be stepped if you are in a state where you begin a write transaction and the transaction is invalid.
The statement can be executed if you don't start explicit transaction, or it's a read transaction.

> 
> > Source/WebCore/platform/sql/SQLiteDatabase.h:163
> > +    SQLiteTransaction* writeTransactionInProgress() const { return m_writeTransactionInProgress; }
> 
> Having a getter start with "write" seems a bit confusing to me.

Will rename it to hasWriteTransactionInProgress.

> 
> > Source/WebCore/platform/sql/SQLiteDatabase.h:179
> > +    SQLiteTransaction* m_writeTransactionInProgress { nullptr };
> 
> We store store raw pointers as data members anymore. This is a security bug
> waiting to happen. If you really need a pointer, it should probably be a
> WeakPtr.

Will update.

> 
> > Source/WebCore/platform/sql/SQLiteTransaction.h:47
> > +    bool rolledBackBySQLite() const;
> 
> How is this new name a progression? Seems to go against WebKit coding style
> that states we should use prefixes for booleans.

Will revert.
Comment 9 Sihui Liu 2021-07-09 12:02:18 PDT
Created attachment 433230 [details]
Patch
Comment 10 Sihui Liu 2021-07-09 12:09:45 PDT
Created attachment 433231 [details]
Patch
Comment 11 Sihui Liu 2021-07-09 12:27:24 PDT
Created attachment 433232 [details]
Patch
Comment 12 Sihui Liu 2021-07-13 17:43:40 PDT
Created attachment 433465 [details]
Patch
Comment 13 Radar WebKit Bug Importer 2021-07-14 14:14:25 PDT
<rdar://problem/80596229>