Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ private void acquireWithinEventExecutor(final Promise<Channel> acquirePromise) {
this.acquireWithinEventExecutor(acquirePromise);
}
} else {
// If the deferred acquirePromise is cancelled, remove it from pendingAcquisitionPromises
// to allow garbage collection.
acquirePromise.addListener(future -> {
if (future.isCancelled()) {
pendingAcquisitionPromises.remove(acquirePromise);
}
});

// We don't have any connections ready to go, and don't have any more capacity to create new
// channels. Add this acquisition to the queue waiting for channels to become available.
pendingAcquisitionPromises.add(acquirePromise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public <T extends ApnsPushNotification> PushNotificationFuture<T, PushNotificati
if (!this.isClosed.get()) {
final long start = System.nanoTime();

this.channelPool.acquire().addListener((GenericFutureListener<Future<Channel>>) acquireFuture -> {
Future<Channel> acquirePromise = this.channelPool.acquire();
acquirePromise.addListener((GenericFutureListener<Future<Channel>>) acquireFuture -> {
if (acquireFuture.isSuccess()) {
final Channel channel = acquireFuture.getNow();

Expand All @@ -207,6 +208,12 @@ public <T extends ApnsPushNotification> PushNotificationFuture<T, PushNotificati
ApnsClient.this.metricsListener.handleNotificationAcknowledged(response, end - start);
} else {
ApnsClient.this.metricsListener.handleWriteFailure(notification.getTopic());

// Try cancel acquirePromise if responseFuture fails (e.g. TimeoutException)
// before acquirePromise gets resolved.
if (acquirePromise.isCancellable()) {
acquirePromise.cancel(true);
}
}
});
} else {
Expand Down