System.Data.SQLite

Check-in [2a6ee97694]
Login

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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2a6ee97694a128c89d4a0db70a2405216dfb4437
User & Date: mistachkin 2012-05-03 19:21:11.425
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
Unified Diff Show Whitespace Changes Patch
Changes to System.Data.SQLite/SQLiteConnectionPool.cs.
145
146
147
148
149
150
151

152
153
154
155
156
157

158
159
160
161
162
163
164
        // Try and get a pooled connection from the queue
        Queue<WeakReference> poolQueue = queue.Queue;
        if (poolQueue == null) return null;

        while (poolQueue.Count > 0)
        {
          WeakReference cnn = poolQueue.Dequeue();

          SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
          if ((hdl != null) && !hdl.IsClosed && !hdl.IsInvalid)
          {
            Interlocked.Increment(ref _poolOpened);
            return hdl;
          }

          GC.KeepAlive(hdl);
        }
        return null;
      }
    }

    /// <summary>







>






>







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
        // Try and get a pooled connection from the queue
        Queue<WeakReference> poolQueue = queue.Queue;
        if (poolQueue == null) return null;

        while (poolQueue.Count > 0)
        {
          WeakReference cnn = poolQueue.Dequeue();
          if (cnn == null) continue;
          SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
          if ((hdl != null) && !hdl.IsClosed && !hdl.IsInvalid)
          {
            Interlocked.Increment(ref _poolOpened);
            return hdl;
          }
          cnn.Target = null;
          GC.KeepAlive(hdl);
        }
        return null;
      }
    }

    /// <summary>
175
176
177
178
179
180
181

182
183
184
185
186

187
188
189
190
191
192
193
            continue;

          Queue<WeakReference> poolQueue = pair.Value.Queue;

          while (poolQueue.Count > 0)
          {
            WeakReference cnn = poolQueue.Dequeue();

            SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
            if (hdl != null)
            {
              hdl.Dispose();
            }

            GC.KeepAlive(hdl);
          }
          
          // Keep track of the highest revision so we can go one higher when we're finished
          if (_poolVersion <= pair.Value.PoolVersion)
            _poolVersion = pair.Value.PoolVersion + 1;
        }







>





>







177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
            continue;

          Queue<WeakReference> poolQueue = pair.Value.Queue;

          while (poolQueue.Count > 0)
          {
            WeakReference cnn = poolQueue.Dequeue();
            if (cnn == null) continue;
            SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
            if (hdl != null)
            {
              hdl.Dispose();
            }
            cnn.Target = null;
            GC.KeepAlive(hdl);
          }
          
          // Keep track of the highest revision so we can go one higher when we're finished
          if (_poolVersion <= pair.Value.PoolVersion)
            _poolVersion = pair.Value.PoolVersion + 1;
        }
215
216
217
218
219
220
221

222
223
224
225
226

227
228
229
230
231
232
233

          Queue<WeakReference> poolQueue = queue.Queue;
          if (poolQueue == null) return;

          while (poolQueue.Count > 0)
          {
            WeakReference cnn = poolQueue.Dequeue();

            SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
            if (hdl != null)
            {
              hdl.Dispose();
            }

            GC.KeepAlive(hdl);
          }
        }
      }
    }

    /// <summary>







>





>







219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

          Queue<WeakReference> poolQueue = queue.Queue;
          if (poolQueue == null) return;

          while (poolQueue.Count > 0)
          {
            WeakReference cnn = poolQueue.Dequeue();
            if (cnn == null) continue;
            SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
            if (hdl != null)
            {
              hdl.Dispose();
            }
            cnn.Target = null;
            GC.KeepAlive(hdl);
          }
        }
      }
    }

    /// <summary>
278
279
280
281
282
283
284

285
286
287
288
289

290
291
292
293
294

      Queue<WeakReference> poolQueue = queue.Queue;
      if (poolQueue == null) return;

      while (poolQueue.Count > target)
      {
        WeakReference cnn = poolQueue.Dequeue();

        SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
        if (hdl != null)
        {
          hdl.Dispose();
        }

        GC.KeepAlive(hdl);
      }
    }
  }
}







>





>





284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

      Queue<WeakReference> poolQueue = queue.Queue;
      if (poolQueue == null) return;

      while (poolQueue.Count > target)
      {
        WeakReference cnn = poolQueue.Dequeue();
        if (cnn == null) continue;
        SQLiteConnectionHandle hdl = cnn.Target as SQLiteConnectionHandle;
        if (hdl != null)
        {
          hdl.Dispose();
        }
        cnn.Target = null;
        GC.KeepAlive(hdl);
      }
    }
  }
}