You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: session-and-channel-pool-configuration.md
+81
Original file line number
Diff line number
Diff line change
@@ -281,3 +281,84 @@ This will cause the following to happen internally in the client library:
281
281
1. The `TransactionRunner` will automatically commit the transaction if the supplied user code
282
282
finished without any errors. The `Commit` RPC that is invoked uses a thread from the default gRPC
283
283
thread pool.
284
+
285
+
### Session Leak
286
+
A `DatabaseClient` object of the Client Library has a limit on the number of maximum sessions. For example the
287
+
default value of `MaxSessions` in the Java Client Library is 400. You can configure these values at the time of
288
+
creating a `Spanner` instance by setting custom `SessionPoolOptions`. When all the sessions are checked
289
+
out of the session pool, every new transaction has to wait until a session is returned to the pool.
290
+
If a session is never returned to the pool (hence causing a session leak), the transactions will have to wait
291
+
indefinitely and your application will be blocked.
292
+
293
+
#### Common Root Causes
294
+
The most common reason for session leaks in the Java client library are:
295
+
1. Not closing a `ResultSet` that is returned by `executeQuery`. Always put `ResultSet` objects in a try-with-resources block, or take other measures to ensure that the `ResultSet` is always closed.
296
+
2. Not closing a `ReadOnlyTransaction` when you no longer need it. Always put `ReadOnlyTransaction` objects in a try-with-resources block, or take other measures to ensure that the `ReadOnlyTransaction` is always closed.
297
+
3. Not closing a `TransactionManager` when you no longer need it. Always put `TransactionManager` objects in a try-with-resources block, or take other measures to ensure that the `TransactionManager` is always closed.
298
+
299
+
As shown in the example below, the `try-with-resources` block releases the session after it is complete.
300
+
If you don't use `try-with-resources` block, unless you explicitly call the `close()` method on all resources
301
+
such as `ResultSet`, the session is not released back to the pool.
0 commit comments