Skip to content

Commit

Permalink
Attach write failure listeners unconditionally. (fixes #725)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchambers committed Feb 15, 2020
1 parent 96227fe commit 1fb095b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pushy/src/main/java/com/turo/pushy/apns/ApnsClientHandler.java
Expand Up @@ -160,7 +160,20 @@ public ApnsClientHandler build() {
@Override
public void write(final ChannelHandlerContext context, final Object message, final ChannelPromise writePromise) {
if (message instanceof PushNotificationPromise) {
this.writePushNotification(context, (PushNotificationPromise) message, writePromise);
final PushNotificationPromise pushNotificationPromise = (PushNotificationPromise) message;

writePromise.addListener(new GenericFutureListener<ChannelPromise>() {

@Override
public void operationComplete(final ChannelPromise future) {
if (!future.isSuccess()) {
log.trace("Failed to write push notification.", future.cause());
pushNotificationPromise.tryFailure(future.cause());
}
}
});

this.writePushNotification(context, pushNotificationPromise, writePromise);
} else {
// This should never happen, but in case some foreign debris winds up in the pipeline, just pass it through.
log.error("Unexpected object in pipeline: {}", message);
Expand Down Expand Up @@ -205,17 +218,6 @@ private void writePushNotification(final ChannelHandlerContext context, final Pu
final PromiseCombiner promiseCombiner = new PromiseCombiner();
promiseCombiner.addAll((ChannelFuture) headersPromise, dataPromise);
promiseCombiner.finish(writePromise);

writePromise.addListener(new GenericFutureListener<ChannelPromise>() {

@Override
public void operationComplete(final ChannelPromise future) {
if (!future.isSuccess()) {
log.trace("Failed to write push notification on stream {}.", streamId, future.cause());
responsePromise.tryFailure(future.cause());
}
}
});
} else {
// This is very unlikely, but in the event that we run out of stream IDs, we need to open a new
// connection. Just closing the context should be enough; automatic reconnection should take things
Expand Down

0 comments on commit 1fb095b

Please sign in to comment.