System.Data.SQLite
Check-in [0dc736558b]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work in progress on ticket [5cee5409f8]: use the enlistment lock to protect against several race conditions between SQLiteEnlistment and SQLiteConnection.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-5cee5409f8
Files: files | file ages | folders
SHA1: 0dc736558bf624b9a5e6b18ab7a5f001ae7122c4
User & Date: mistachkin 2018-01-25 19:21:39
Context
2018-01-25
20:44
Prevent NullReferenceException being raised from within SQLiteConnection.Close() due to those fields being invalidated by SQLiteEnlistment. check-in: 6d391f764a user: mistachkin tags: tkt-5cee5409f8
19:21
Work in progress on ticket [5cee5409f8]: use the enlistment lock to protect against several race conditions between SQLiteEnlistment and SQLiteConnection. check-in: 0dc736558b user: mistachkin tags: tkt-5cee5409f8
18:56
Merge updates from trunk. check-in: 686803b92e user: mistachkin tags: tkt-5cee5409f8
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteEnlistment.cs.

180
181
182
183
184
185
186
187
188
189
190
191
192
193


194


195
196

197












198
199
200
201




202
203
204
205
206
207
208
209
210
211
212
213
214
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240


241


242
243

244










245





246
247
248
249
250
251
252
253
254
255
256
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region IEnlistmentNotification Members
    public void Commit(Enlistment enlistment)
    {
      CheckDisposed();

      SQLiteConnection cnn = _transaction.Connection;

      lock (cnn._enlistmentSyncRoot)
      {
          cnn._enlistment = null;


      }



      try

      {












        _transaction.IsValid(true);
        _transaction.Connection._transactionLevel = 1;
        _transaction.Commit();





        enlistment.Done();
      }
      finally
      {
        Cleanup(cnn);
      }
    }

    ///////////////////////////////////////////////////////////////////////////

    public void InDoubt(Enlistment enlistment)
    {
      CheckDisposed();
................................................................................
        preparingEnlistment.Prepared();
    }

    ///////////////////////////////////////////////////////////////////////////

    public void Rollback(Enlistment enlistment)
    {
      CheckDisposed();

      SQLiteConnection cnn = _transaction.Connection;

      lock (cnn._enlistmentSyncRoot)
      {
          cnn._enlistment = null;


      }



      try

      {










        _transaction.Rollback();





        enlistment.Done();
      }
      finally
      {
        Cleanup(cnn);
      }
    }
    #endregion
  }
}
#endif // !PLATFORM_COMPACT_FRAMEWORK







|

|

|
|
|
>
>
|
>
>

<
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|

>
>
>
>
|
|
|
|
|
|







 







|

|

|
|
|
>
>
|
>
>

<
>
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
|
|
|
|
|





180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region IEnlistmentNotification Members
    public void Commit(Enlistment enlistment)
    {
        CheckDisposed();

        SQLiteConnection cnn = null;

        try
        {
            while (true)
            {
                cnn = _transaction.Connection;

                if (cnn == null)
                    break;


                lock (cnn._enlistmentSyncRoot) /* TRANSACTIONAL */
                {
                    //
                    // NOTE: This check is necessary to detect the case where
                    //       the SQLiteConnection.Close() method changes the
                    //       connection associated with our transaction (i.e.
                    //       to avoid a race (condition) between grabbing the
                    //       Connection property and locking its enlistment).
                    //
                    if (!Object.ReferenceEquals(cnn, _transaction.Connection))
                        continue;

                    cnn._enlistment = null;

                    _transaction.IsValid(true); /* throw */
                    cnn._transactionLevel = 1;
                    _transaction.Commit();

                    break;
                }
            }

            enlistment.Done();
        }
        finally
        {
            Cleanup(cnn);
        }
    }

    ///////////////////////////////////////////////////////////////////////////

    public void InDoubt(Enlistment enlistment)
    {
      CheckDisposed();
................................................................................
        preparingEnlistment.Prepared();
    }

    ///////////////////////////////////////////////////////////////////////////

    public void Rollback(Enlistment enlistment)
    {
        CheckDisposed();

        SQLiteConnection cnn = null;

        try
        {
            while (true)
            {
                cnn = _transaction.Connection;

                if (cnn == null)
                    break;


                lock (cnn._enlistmentSyncRoot) /* TRANSACTIONAL */
                {
                    //
                    // NOTE: This check is necessary to detect the case where
                    //       the SQLiteConnection.Close() method changes the
                    //       connection associated with our transaction (i.e.
                    //       to avoid a race (condition) between grabbing the
                    //       Connection property and locking its enlistment).
                    //
                    if (!Object.ReferenceEquals(cnn, _transaction.Connection))
                        continue;

                    _transaction.Rollback();

                    break;
                }
            }

            enlistment.Done();
        }
        finally
        {
            Cleanup(cnn);
        }
    }
    #endregion
  }
}
#endif // !PLATFORM_COMPACT_FRAMEWORK

Changes to System.Data.SQLite/SQLiteTransactionBase.cs.

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        /// <summary>
        /// Gets the isolation level of the transaction.  SQLite only supports Serializable transactions.
        /// </summary>
        public override IsolationLevel IsolationLevel
        {
            get { CheckDisposed(); return _level; }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
        {
#if THROW_ON_DISPOSED







|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        /// <summary>
        /// Gets the isolation level of the transaction.  SQLite only supports Serializable transactions.
        /// </summary>
        public override IsolationLevel IsolationLevel
        {
            get { CheckDisposed(); return _level; }
        }

        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region IDisposable "Pattern" Members
        private bool disposed;
        private void CheckDisposed() /* throw */
        {
#if THROW_ON_DISPOSED