System.Data.SQLite
Check-in [2a6ee97694]
Not logged in

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

Overview
Comment:Check each weak reference object from the queue prior to attempting to fetch its target.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2a6ee97694a128c89d4a0db70a2405216dfb4437
User & Date: mistachkin 2012-05-03 19:21:11
Context
2012-05-04
16:04
Prevent returning a connection handle whose finalizer may be pending on the GC thread. Part of fix for ticket [996d13cd87]. Also, update Eagle in externals to latest trunk. check-in: 5c0646db9d user: mistachkin tags: trunk
2012-05-03
19:21
Check each weak reference object from the queue prior to attempting to fetch its target. check-in: 2a6ee97694 user: mistachkin tags: trunk
17:46
Update test case for ticket [996d13cd87] to run with and without connection pooling enabled. check-in: ead1f27df0 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

   145    145           // Try and get a pooled connection from the queue
   146    146           Queue<WeakReference> poolQueue = queue.Queue;
   147    147           if (poolQueue == null) return null;
   148    148   
   149    149           while (poolQueue.Count > 0)
   150    150           {
   151    151             WeakReference cnn = poolQueue.Dequeue();
          152  +          if (cnn == null) continue;
   152    153             SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
   153    154             if ((hdl != null) && !hdl.IsClosed && !hdl.IsInvalid)
   154    155             {
   155    156               Interlocked.Increment(ref _poolOpened);
   156    157               return hdl;
   157    158             }
          159  +          cnn.Target = null;
   158    160             GC.KeepAlive(hdl);
   159    161           }
   160    162           return null;
   161    163         }
   162    164       }
   163    165   
   164    166       /// <summary>
................................................................................
   175    177               continue;
   176    178   
   177    179             Queue<WeakReference> poolQueue = pair.Value.Queue;
   178    180   
   179    181             while (poolQueue.Count > 0)
   180    182             {
   181    183               WeakReference cnn = poolQueue.Dequeue();
          184  +            if (cnn == null) continue;
   182    185               SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
   183    186               if (hdl != null)
   184    187               {
   185    188                 hdl.Dispose();
   186    189               }
          190  +            cnn.Target = null;
   187    191               GC.KeepAlive(hdl);
   188    192             }
   189    193             
   190    194             // Keep track of the highest revision so we can go one higher when we're finished
   191    195             if (_poolVersion <= pair.Value.PoolVersion)
   192    196               _poolVersion = pair.Value.PoolVersion + 1;
   193    197           }
................................................................................
   215    219   
   216    220             Queue<WeakReference> poolQueue = queue.Queue;
   217    221             if (poolQueue == null) return;
   218    222   
   219    223             while (poolQueue.Count > 0)
   220    224             {
   221    225               WeakReference cnn = poolQueue.Dequeue();
          226  +            if (cnn == null) continue;
   222    227               SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
   223    228               if (hdl != null)
   224    229               {
   225    230                 hdl.Dispose();
   226    231               }
          232  +            cnn.Target = null;
   227    233               GC.KeepAlive(hdl);
   228    234             }
   229    235           }
   230    236         }
   231    237       }
   232    238   
   233    239       /// <summary>
................................................................................
   278    284   
   279    285         Queue<WeakReference> poolQueue = queue.Queue;
   280    286         if (poolQueue == null) return;
   281    287   
   282    288         while (poolQueue.Count > target)
   283    289         {
   284    290           WeakReference cnn = poolQueue.Dequeue();
          291  +        if (cnn == null) continue;
   285    292           SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
   286    293           if (hdl != null)
   287    294           {
   288    295             hdl.Dispose();
   289    296           }
          297  +        cnn.Target = null;
   290    298           GC.KeepAlive(hdl);
   291    299         }
   292    300       }
   293    301     }
   294    302   }