7
7
8
8
import java .sql .ResultSet ;
9
9
import java .util .List ;
10
+ import java .util .concurrent .CompletableFuture ;
10
11
import java .util .concurrent .CompletionStage ;
11
12
import java .util .function .Function ;
12
13
@@ -24,6 +25,7 @@ final class ProxyConnection implements ReactiveConnection {
24
25
private final ReactiveConnectionPool sqlClientPool ;
25
26
private ReactiveConnection connection ;
26
27
private boolean connected ;
28
+ private boolean closed ;
27
29
private final String tenantId ;
28
30
29
31
public ProxyConnection (ReactiveConnectionPool sqlClientPool ) {
@@ -38,6 +40,11 @@ public ProxyConnection(ReactiveConnectionPool sqlClientPool, String tenantId) {
38
40
39
41
private <T > CompletionStage <T > withConnection (Function <ReactiveConnection , CompletionStage <T >> operation ) {
40
42
assertUseOnEventLoop ();
43
+ if ( closed ) {
44
+ CompletableFuture <T > ret = new CompletableFuture <>();
45
+ ret .completeExceptionally ( new IllegalStateException ( "session is closed" ) );
46
+ return ret ;
47
+ }
41
48
if ( !connected ) {
42
49
connected = true ; // we're not allowed to fetch two connections!
43
50
CompletionStage <ReactiveConnection > connection =
@@ -49,7 +56,9 @@ private <T> CompletionStage<T> withConnection(Function<ReactiveConnection, Compl
49
56
if ( connection == null ) {
50
57
// we're already in the process of fetching a connection,
51
58
// so this must be an illegal concurrent call
52
- throw new IllegalStateException ( "session is currently connecting to database" );
59
+ CompletableFuture <T > ret = new CompletableFuture <>();
60
+ ret .completeExceptionally ( new IllegalStateException ( "session is currently connecting to database" ) );
61
+ return ret ;
53
62
}
54
63
return operation .apply ( connection );
55
64
}
@@ -140,6 +149,7 @@ public void close() {
140
149
connection .close ();
141
150
connection = null ;
142
151
}
152
+ closed = true ;
143
153
}
144
154
145
155
}
0 commit comments