|
20 | 20 |
|
21 | 21 | import io.netty.util.concurrent.DefaultThreadFactory; |
22 | 22 | import java.sql.SQLException; |
23 | | -import java.util.List; |
| 23 | +import java.util.ArrayList; |
24 | 24 | import java.util.Properties; |
25 | 25 | import java.util.concurrent.ExecutorService; |
26 | 26 | import java.util.concurrent.Executors; |
@@ -183,17 +183,26 @@ public Properties getClientInfo() { |
183 | 183 | public void close() throws SQLException { |
184 | 184 | Exception topLevelException = null; |
185 | 185 | try { |
186 | | - AutoCloseables.close(List.copyOf(statementMap.values())); |
| 186 | + if (executorService != null) { |
| 187 | + executorService.shutdown(); |
| 188 | + } |
187 | 189 | } catch (final Exception e) { |
188 | 190 | topLevelException = e; |
189 | 191 | } |
| 192 | + ArrayList<AutoCloseable> closeables = new ArrayList<>(statementMap.values()); |
| 193 | + closeables.add(clientHandler); |
| 194 | + closeables.addAll(allocator.getChildAllocators()); |
| 195 | + closeables.add(allocator); |
190 | 196 | try { |
191 | | - AutoCloseables.close(clientHandler); |
192 | | - if (executorService != null) { |
193 | | - executorService.shutdown(); |
| 197 | + AutoCloseables.close(closeables); |
| 198 | + } catch (final Exception e) { |
| 199 | + if (topLevelException == null) { |
| 200 | + topLevelException = e; |
| 201 | + } else { |
| 202 | + topLevelException.addSuppressed(e); |
194 | 203 | } |
195 | | - allocator.getChildAllocators().forEach(AutoCloseables::closeNoChecked); |
196 | | - AutoCloseables.close(allocator); |
| 204 | + } |
| 205 | + try { |
197 | 206 | super.close(); |
198 | 207 | } catch (final Exception e) { |
199 | 208 | if (topLevelException == null) { |
|
0 commit comments