question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

URI("pulsar://broker-:6650").getPort() will return "-1" instead of 6650

See original GitHub issue

found this by wrongly set hostname to “broker-”, while using docker to do some test, not sure if this is a bug in java.net.URI. while after change hostname to “broker-1”, it worked fine to get 6650.

Expected behavior

In this part of code,

   public BrokerService(PulsarService pulsar) throws Exception {
        this.pulsar = pulsar;
        this.managedLedgerFactory = pulsar.getManagedLedgerFactory();
        this.port = new URI(pulsar.getBrokerServiceUrl()).getPort();
        this.tlsPort = new URI(pulsar.getBrokerServiceUrlTls()).getPort();
...

URI(“pulsar://broker-:6650”).getPort() should return 6650

Actual behavior

URI(“pulsar://broker-:6650”).getPort() will return “-1”

Steps to reproduce

set hostname to “broker-”, start broker on this host, it will report wrong port:

2018-01-03 02:13:14,778 - INFO  - [main:DistributedIdGenerator@79] - Created sequential node at /counters/producer-name/-0000000000 -- Generator Id is test_zj-0
2018-01-03 02:13:14,781 - ERROR - [main:PulsarService@345] - port out of range:-1
java.lang.IllegalArgumentException: port out of range:-1
    at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
    at java.net.InetSocketAddress.<init>(InetSocketAddress.java:224)
    at org.apache.pulsar.broker.service.BrokerService.start(BrokerService.java:285)
    at org.apache.pulsar.broker.PulsarService.start(PulsarService.java:270)
    at org.apache.pulsar.PulsarBrokerStarter$BrokerStarter.start(PulsarBrokerStarter.java:190)

the docker command that I wrongly set hostname is this:

docker run -it\
		--network pulsar_network \
	    --volume /tmp/test_bk/broker-/journal:/data/journal \
	    --volume /tmp/test_bk/broker-/ledger:/data/ledger \
	    --volume /tmp/test_bk/broker-/index:/data/index \
	    --name "broker-" \
	    --hostname "broker-" \
	    --env zkServers=192.168.123.71:2181 \
	    --env zookeeperServers=192.168.123.71:2181 \
	    --env globalZookeeperServers=192.168.123.71:2181 \
	    --env clusterName=test_zhaijia \
	    --env statsProviderClass=org.apache.bookkeeper.stats.NullStatsProvider \
	    --env zkLedgersRootPath=/ledgers \
            bin/apply-config-from-env.py conf/broker.conf &&  bin/apply-config-from-env.py conf/pulsar_env.sh && bin/apply-config-from-env.py conf/bookkeeper.conf  && bin/pulsar broker

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
sijiecommented, Jan 4, 2018

as discussed, we might consider documenting what special characters can’t be used in pulsar service uri.

1reaction
ppgomlcommented, Aug 30, 2019

It seems I cannot use ‘_’ in host. (new URI(“pulsar://tkiot_pulsar1:6650”)).getPort() returns -1

I found this useful link. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=5049974

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the port from IPv6 Uri? - Stack Overflow
getPort() returns -1 instead of 1234. How can the port of a Uri obtained without parsing the Uri's string? android · android-networking.
Read more >
java.net.URI.getPort java code examples - Tabnine
Returns the port number of this URI, or -1 if this URI has no explicit port. Popular methods of URI. <init>. Constructs a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found