Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE fix for closing with pending AckClosure(s) on Android #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ambientlabs
Copy link

Calling publish on an instance of StreamingConnection with an AckHandler can result in NPEs if the connection is closed before ACKs have been sent. The result should be an "java.lang.IllegalStateException: stan: connection closed"; however, the result in an NPE.

Note: I am working on Android using Kotlin.

  val opts: Options? = Options.Builder().natsUrl("nats://10.0.2.2:4222").clientId("android-client").clusterId("test-cluster").build()
        val cf = StreamingConnectionFactory(opts)
        val sc = cf.createConnection()

        // Note: Proving an AckHandler can result in NPEs when closing the StreamingConnection
        sc.publish("foo", "Hello World".toByteArray(), AckHandler { nuid, ex ->
            Log.i("Test", "Ack for nuid $nuid and ex $ex")
        })

        uiScope.launch {
            val r = Random()
            var count = 10
            while (count-- > 0) {
                var message = "Value: ${r.nextInt(10000)}"
                // Note: Proving an AckHandler can result in NPEs when closing the StreamingConnection
                sc.publish("foo", "Message $count: ${message}".toByteArray(), AckHandler { nuid, ex ->
                    Log.i("Test", "Ack for nuid $nuid and ex $ex")
                })

                delay(100)
                // Introduce an early close to generate an NPE rather than an IllegalStateException
                sc.close()
            }
            sc.close()
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant