HEROLABS / herolabs-apns

A small library to user with the Apple push notification service
24 stars 18 forks source link

feedback prevents clojure process from terminating #11

Open lbeschastny opened 10 years ago

lbeschastny commented 10 years ago

Hi.

I found another problem with herolabs-apns.

After calling apns feedback service, it leaves some resource open (probably, some connection), thus preventing graceful termination of clojure process.

Here is my code to reproduce this problem:

(ns apns-test.core
  (:require [herolabs.apns.ssl  :as ssl ]
            [clojure.java.io    :as io  ])
  (:use herolabs.apns.feedback))

(defn -main []
  (let [store (ssl/keystore
                :key-path (io/resource "my-project.p12")
                :cert-path (io/resource "my-project.cer"))
        tm    (ssl/naive-trust-managers
                :trace true)
        ctx   (ssl/ssl-context
                :trust-managers tm
                :keystore       store)]
    (println "Fetching feedback...")
    (doseq [[token timestamp] (feedback (dev-address) ctx)]
      (println timestamp ":" token))
    (println "Terminating...")))
lbeschastny commented 10 years ago

I found a way to solve this problem for myself:

First, I'm creating my own event loop group:

(let [el (NioEventLoopGroup.)]
  ...

Then I'm calling feedback wit this event loop group:

(feedback (dev-address) ctx :event-loop el)

Finally, I'm terminating event loop group after after processing the whole sequence of feedbacks:

(.shutdown el)

Here is the full code example:

(defn -main []
  (let [store (ssl/keystore
                :key-path (io/resource "my-project.p12")
                :cert-path (io/resource "my-project.cer"))
        tm    (ssl/naive-trust-managers
                :trace true)
        ctx   (ssl/ssl-context
                :trust-managers tm
                :keystore       store)
        el    (NioEventLoopGroup.)]
    (println "Fetching feedback...")
    (doseq [[token timestamp] (feedback (dev-address) ctx :event-loop el)]
      (println timestamp ":" token))
    (println "Terminating...")
    (.shutdownGracefully el)))
lbeschastny commented 10 years ago

It looks like event loop continues to listen to some IO resource even after APNS connection is closed.

Probably, Netty leaves something in an event loop, which is not being cleaned up.