mwkirk / javapns

Test import of svn javapns repo from Google Code
3 stars 0 forks source link

Starting a PushQueue with multiple threads and InputStream parameter throws a Stream closed exception #87

Closed mwkirk closed 11 years ago

mwkirk commented 11 years ago

Original author: thomas...@googlemail.com (November 29, 2011 14:04:42)

What steps will reproduce the problem?

Create a PushQueue with multiple threads like this:

Push.queue(NotificationQueues.class.getResourceAsStream("....p12"), KEYSTORE_PASSWORD, false, NUM_THREADS);

What is the expected output? What do you see instead?

You will get the following exception for each started thread except the first one:

javapns.communication.exceptions.KeystoreException: Keystore exception: Stream closed at javapns.communication.KeystoreManager.wrapKeystoreException(KeystoreManager.java:164) at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:66) at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:42) at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:29) at javapns.communication.ConnectionToAppleServer.<init>(ConnectionToAppleServer.java:54) at javapns.notification.ConnectionToNotificationServer.<init>(ConnectionToNotificationServer.java:16) at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:107) at javapns.notification.transmission.NotificationThread.runQueue(NotificationThread.java:255) at javapns.notification.transmission.NotificationThread.run(NotificationThread.java:200) at java.lang.Thread.run(Thread.java:680) Caused by: java.io.IOException: Stream closed at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145) at java.io.BufferedInputStream.fill(BufferedInputStream.java:189) at java.io.BufferedInputStream.read(BufferedInputStream.java:237) at sun.security.util.DerValue.init(DerValue.java:345) at sun.security.util.DerValue.<init>(DerValue.java:303) at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1200) at java.security.KeyStore.load(KeyStore.java:1185) at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:64) ... 8 more

What version of the product are you using? On what operating system?

javapns 2.1, MacOS X 10.7.2, java 1.6.0_29

Original issue: http://code.google.com/p/javapns/issues/detail?id=87

mwkirk commented 11 years ago

From sype...@gmail.com on November 29, 2011 15:53:29 Thank you for the report. Indeed, providing an InputStream for the keystore appears to work only for a single thread, as other threads are then given a depleted stream. A temporary workaround is to provide the keystore as a byte[] array, a File or a KeyStore object. A permanent solution will be added in an upcoming release.

mwkirk commented 11 years ago

From sype...@gmail.com on November 30, 2011 13:53:50 Fixed in revision 340 (2.1.1a1)

The AppleServerBasicImpl class will now automatically ensure that the keystore reference provided is reusable. If it is an InputStream, it will be preloaded as a KeyStore object so that other threads don't get a depleted stream.