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

.NullPointerException: Cannot invoke "java.io.InputStream.available()" because "this.val$is" is null #3578

Closed
imalik8088 opened this issue Nov 10, 2021 · 6 comments

Comments

@imalik8088
Copy link

Hi there, I've got the the following error using the following example in https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/kubectl/equivalents/PodExecEquivalent.java

2021-11-10 14:50:13,115 ERROR [io.fab.kub.cli.uti.InputStreamPumper] (pool-16-thread-1) Error while pumping stream.: java.lang.NullPointerException: Cannot invoke "java.io.InputStream.available()" because "this.val$is" is null
	at io.fabric8.kubernetes.client.utils.InputStreamPumper$1.read(InputStreamPumper.java:53)
	at io.fabric8.kubernetes.client.utils.InputStreamPumper.transferTo(InputStreamPumper.java:76)
	at io.fabric8.kubernetes.client.utils.InputStreamPumper.lambda$pump$0(InputStreamPumper.java:89)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

Here is my code:

class Foo{
    val execLatch = CountDownLatch(1);
    private val LOG: Logger = LoggerFactory.getLogger(Foo::class.java)

    fun doSomething(): Unit {
        val out = ByteArrayOutputStream()
        val error = ByteArrayOutputStream()

        val execWatch = kubernetesClient.pods()
            .inNamespace(kubernetesClient.namespace)
            .withName("MY-POD")
            .inContainer("MY-CONTAINER")
            .writingOutput(out)
            .writingError(error)
            .usingListener(MyPodExecListener())
            .exec("du", "-s", "/home/abcd")

        val latchTerminationStatus: Boolean = execLatch.await(5, TimeUnit.SECONDS)
        if (!latchTerminationStatus) {
            LOG.warn("Latch could not terminate within specified time")
        }
        LOG.info("Exec Output: {} ", out)
        execWatch.close()
    }

    inner class MyPodExecListener : ExecListener {

        override fun onOpen(response: okhttp3.Response?) {
            println(response)
            LOG.info("Shell was opened")
        }

        override fun onFailure(t: Throwable?, response: okhttp3.Response?) {
            LOG.info("Some error encountered")
            execLatch.countDown()
        }

        override fun onClose(i: Int, s: String) {
            LOG.info("Shell Closing")
            execLatch.countDown()
        }
    }
}
@shawkins
Copy link
Contributor

Should be a duplicate of #3384

@imalik8088
Copy link
Author

muchas gracias for the support that helped. Was using Qarkus 2.3.1 which included 5.7.3 and the mentioned fix is included in 5.8.0 which ist included in Quarkus 2.4.1.

@imalik8088
Copy link
Author

Perhaps something related to this topic, If I call the endpoint/method. At first run it shows the output in afterwards it doesnt:


2021-11-10 17:34:32,170 INFO  [io.xxx.xxx.ser.KubernetesService] (OkHttp https://rancher-dev.xxx.io/...) Shell was opened
2021-11-10 17:34:32,172 INFO  [io.xxx.xxx.ser.KubernetesService] (OkHttp https://rancher-dev.xxx.io/...) Shell Closing
2021-11-10 17:34:32,172 INFO  [io.xxx.xxx.ser.KubernetesService] (executor-thread-0) Exec Output: 9.7M	/home/jovyan

2021-11-10 17:34:34,431 INFO  [io.xxx.xxx.ser.KubernetesService] (OkHttp https://rancher-dev.xxx.io/...) Shell was opened
2021-11-10 17:34:34,431 INFO  [io.xxx.xxx.ser.KubernetesService] (executor-thread-0) Exec Output:
2021-11-10 17:34:34,432 INFO  [io.xxx.xxx.ser.KubernetesService] (executor-thread-0) Shell Closing
2021-11-10 17:34:36,878 INFO  [io.xxx.xxx.ser.KubernetesService] (OkHttp https://rancher-dev.xxx.io/...) Shell was opened
2021-11-10 17:34:36,878 INFO  [io.xxx.xxx.ser.KubernetesService] (executor-thread-0) Exec Output:
2021-11-10 17:34:36,878 INFO  [io.xxx.xxx.ser.KubernetesService] (executor-thread-0) Shell Closing

@imalik8088 imalik8088 reopened this Nov 10, 2021
@shawkins
Copy link
Contributor

I don't follow why this was reopened - are you running on a later version and still seeing the log of the npe?

@imalik8088
Copy link
Author

I dont the NPE but and unexpected behavior, In the first call it gives me the right output Exec Output: 9.7M after then without an output

@shawkins
Copy link
Contributor

Perhaps something related to this topic, If I call the endpoint/method. At first run it shows the output in afterwards it doesnt:

It's not related to the NPE. I'm not sure if there is a trace level for websocket traffic, if you can't seem to get a log can you put breakpoints in ExecWebSocketListener.onMessage and cleanUpOnce to see if you are getting a message prior to the websocket being closed?

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

No branches or pull requests

2 participants