Pulsar: Receiving "Connection Already Closed Error on Creating Producer"

Created on 17 Oct 2018  路  6Comments  路  Source: apache/pulsar

Expected behavior

I would expect the client to connect and build, or give a more useful error.

Actual behavior

When attempting to create the producer, I receive this error:

Exception in thread "main" org.apache.pulsar.client.api.PulsarClientException: Connection already closed
    at org.apache.pulsar.client.impl.ClientCnx.channelInactive(ClientCnx.java:169)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224)
    at org.apache.pulsar.shade.io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:377)
    at org.apache.pulsar.shade.io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:342)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224)
    at org.apache.pulsar.shade.io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1409)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
    at org.apache.pulsar.shade.io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:927)
    at org.apache.pulsar.shade.io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:822)
    at org.apache.pulsar.shade.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at org.apache.pulsar.shade.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    at org.apache.pulsar.shade.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
    at org.apache.pulsar.shade.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
    at org.apache.pulsar.shade.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:748)

Steps to reproduce

We are not able to reproduce this issue with the python library. Here is the java code:

messageBus = PulsarClient.builder()
                .serviceUrl(messageBusUrl)
                .tlsTrustCertsFilePath("/Users/josh/Documents/myriadmobile/kernel/translator-mono/core/src/main/resources/pulsar-ca-cert.pem")
                .authentication("org.apache.pulsar.client.impl.auth.AuthenticationTls",
                        "tlsCertFile:/Users/josh/Documents/myriadmobile/kernel/translator-mono/core/src/main/resources/pulsar-public.pem,tlsKeyFile:/Users/josh/Documents/myriadmobile/kernel/translator-mono/core/src/main/resources/pulsar-private.pem")
                .build()

System configuration

This was originally encountered with 2.0.1-incubating (as referenced for the import in the java client import), and also persists in 2.1.0 and 2.1.1

componenclient typcleanup typquestion

Most helpful comment

I have the same issue running for Python version 2, pulsar version 2.4.0.
Ubuntu 18.04.2 LTS (Bionic Beaver) running under Virtual Box in Windows 10

import pulsar
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('my-topic')
producer.send("testing")
client.close()

2019-07-16 18:19:47.192 INFO ConnectionPool:72 | Created connection for pulsar://localhost:6650
2019-07-16 18:19:47.193 ERROR ClientConnection:360 | [ -> pulsar://localhost:6650] Failed to establish connection: Connection refused
2019-07-16 18:19:47.193 INFO ClientConnection:1297 | [ -> pulsar://localhost:6650] Connection closed
2019-07-16 18:19:47.193 ERROR ClientImpl:182 | Error Checking/Getting Partition Metadata while creating producer on persistent://public/default/my-topic -- 5
2019-07-16 18:19:47.193 INFO ClientImpl:482 | Closing Pulsar client
Traceback (most recent call last):
producer = client.create_producer('my-topic')
File "/usr/local/lib/python2.7/dist-packages/pulsar/init.py", line 476, in create_producer
p._producer = self._client.create_producer(topic, conf)
Exception: Pulsar error: ConnectError
2019-07-16 18:19:47.200 INFO ClientConnection:222 | [ -> pulsar://localhost:6650] Destroyed connection

changing 'pulsar://localhost:6650' -> 'http://:6650' doesn't work either.
I am really confused with this library.

All 6 comments

@MrThreepwood I think you need to set enableTls to true.

 messageBus = PulsarClient.builder()
                 .serviceUrl(messageBusUrl)
+                .enableTls(true)
                 .tlsTrustCertsFilePath("/Users/josh/Documents/myriadmobile/kernel/translator-mono/core/src/main/resources/pulsar-ca-cert.pem")
                 .authentication("org.apache.pulsar.client.impl.auth.AuthenticationTls",
                         "tlsCertFile:/Users/josh/Documents/myriadmobile/kernel/translator-mono/core/src/main/resources/pulsar-public.pem,tlsKeyFile:/Users/josh/Documents/myriadmobile/kernel/translator-mono/core/src/main/resources/pulsar-private.pem")
                 .build()

This configuration will be unnecessary in 2.2.0 or later.
cf. https://github.com/apache/pulsar/pull/2315

The message is still misleading. It would be good to have something a bit more explicit to say that the client was not able to connect to the remote endpoint.

This appears to be working for me, thanks. It is not mentioned as part of the documentation here however:
https://pulsar.apache.org/docs/latest/security/tls/

I also agree with ivankelly that this is very misleading. Clearly I'm encountering an auth error, so simply closing the connection and throwing the first time I attempt to create a producer or consumer isn't behavior that I would expect.

@MrThreepwood I think the documentation in the latest website is correct. You were checking the old website.

Closing this issue for now. If you need more help from us, feel free to reopen it.

I have the same issue running for Python version 2, pulsar version 2.4.0.
Ubuntu 18.04.2 LTS (Bionic Beaver) running under Virtual Box in Windows 10

import pulsar
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('my-topic')
producer.send("testing")
client.close()

2019-07-16 18:19:47.192 INFO ConnectionPool:72 | Created connection for pulsar://localhost:6650
2019-07-16 18:19:47.193 ERROR ClientConnection:360 | [ -> pulsar://localhost:6650] Failed to establish connection: Connection refused
2019-07-16 18:19:47.193 INFO ClientConnection:1297 | [ -> pulsar://localhost:6650] Connection closed
2019-07-16 18:19:47.193 ERROR ClientImpl:182 | Error Checking/Getting Partition Metadata while creating producer on persistent://public/default/my-topic -- 5
2019-07-16 18:19:47.193 INFO ClientImpl:482 | Closing Pulsar client
Traceback (most recent call last):
producer = client.create_producer('my-topic')
File "/usr/local/lib/python2.7/dist-packages/pulsar/init.py", line 476, in create_producer
p._producer = self._client.create_producer(topic, conf)
Exception: Pulsar error: ConnectError
2019-07-16 18:19:47.200 INFO ClientConnection:222 | [ -> pulsar://localhost:6650] Destroyed connection

changing 'pulsar://localhost:6650' -> 'http://:6650' doesn't work either.
I am really confused with this library.

hi, is the issue above solved? i am confused with that error "Error Checking/Getting Partition Metadata while creating producer" too @gurgen2727

Was this page helpful?
0 / 5 - 0 ratings