[GH-ISSUE #215] AMQP_URI parsing problems if host contains digits (including IP) #116

Closed
opened 2026-02-26 09:36:36 +03:00 by kerem · 7 comments
Owner

Originally created by @Deltachaos on GitHub (Jan 19, 2020).
Original GitHub issue: https://github.com/ONLYOFFICE/Docker-DocumentServer/issues/215

Originally assigned to: @agolybev on GitHub.

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Starting the docker image with AMQP_SERVER_URL that does not contain a port fails because the host is not parsed correctly.

You can reproduce this by extracting the parse_rabbitmq_url function from run-document-server.sh.

#!/bin/bash

parse_rabbitmq_url(){
  local amqp=$1
echo $amqp
  # extract the protocol
  local proto="$(echo $amqp | grep :// | sed -e's,^\(.*://\).*,\1,g')"
  # remove the protocol
  local url="$(echo ${amqp/$proto/})"

  # extract the user and password (if any)
  local userpass="`echo $url | grep @ | cut -d@ -f1`"
  local pass=`echo $userpass | grep : | cut -d: -f2`

  local user
  if [ -n "$pass" ]; then
    user=`echo $userpass | grep : | cut -d: -f1`
  else
    user=$userpass
  fi

  # extract the host
  local hostport="$(echo ${url/$userpass@/} | cut -d/ -f1)"
  # by request - try to extract the port
  local port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"

  local host
  if [ -n "$port" ]; then
    host=`echo $hostport | grep : | cut -d: -f1`
  else
    host=$hostport
    port="5672"
  fi

  # extract the path (if any)
  local path="$(echo $url | grep / | cut -d/ -f2-)"

  AMQP_SERVER_PROTO=${proto:0:-3}
  AMQP_SERVER_HOST=$host
  AMQP_SERVER_USER=$user
  AMQP_SERVER_PASS=$pass
  AMQP_SERVER_PORT=$port

echo "Proto: $AMQP_SERVER_PROTO"
echo "Host: $AMQP_SERVER_HOST"
echo "User: $AMQP_SERVER_USER"
echo "Pass: $AMQP_SERVER_PASS"
echo "Port: $AMQP_SERVER_PORT"

}

parse_rabbitmq_url "amqp://onlyoffice:blalbla@10.0.0.2"

What is the expected behavior?

The script above should produce the following output and the docker image should start properly.

amqp://onlyoffice:blalbla@10.0.0.2:2343
Proto: amqp
Host: 10.0.0.2
User: onlyoffice
Pass: blalbla
Port: 2343

Did this work in previous versions of DocumentServer?

have not tried yet

DocumentServer Docker tag:

129a1d8ef76c

Host Operating System:

Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic

Originally created by @Deltachaos on GitHub (Jan 19, 2020). Original GitHub issue: https://github.com/ONLYOFFICE/Docker-DocumentServer/issues/215 Originally assigned to: @agolybev on GitHub. **Do you want to request a *feature* or report a *bug*?** Bug **What is the current behavior?** Starting the docker image with `AMQP_SERVER_URL` that does not contain a port fails because the host is not parsed correctly. You can reproduce this by extracting the `parse_rabbitmq_url` function from `run-document-server.sh`. ``` #!/bin/bash parse_rabbitmq_url(){ local amqp=$1 echo $amqp # extract the protocol local proto="$(echo $amqp | grep :// | sed -e's,^\(.*://\).*,\1,g')" # remove the protocol local url="$(echo ${amqp/$proto/})" # extract the user and password (if any) local userpass="`echo $url | grep @ | cut -d@ -f1`" local pass=`echo $userpass | grep : | cut -d: -f2` local user if [ -n "$pass" ]; then user=`echo $userpass | grep : | cut -d: -f1` else user=$userpass fi # extract the host local hostport="$(echo ${url/$userpass@/} | cut -d/ -f1)" # by request - try to extract the port local port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" local host if [ -n "$port" ]; then host=`echo $hostport | grep : | cut -d: -f1` else host=$hostport port="5672" fi # extract the path (if any) local path="$(echo $url | grep / | cut -d/ -f2-)" AMQP_SERVER_PROTO=${proto:0:-3} AMQP_SERVER_HOST=$host AMQP_SERVER_USER=$user AMQP_SERVER_PASS=$pass AMQP_SERVER_PORT=$port echo "Proto: $AMQP_SERVER_PROTO" echo "Host: $AMQP_SERVER_HOST" echo "User: $AMQP_SERVER_USER" echo "Pass: $AMQP_SERVER_PASS" echo "Port: $AMQP_SERVER_PORT" } parse_rabbitmq_url "amqp://onlyoffice:blalbla@10.0.0.2" ``` **What is the expected behavior?** The script above should produce the following output and the docker image should start properly. ``` amqp://onlyoffice:blalbla@10.0.0.2:2343 Proto: amqp Host: 10.0.0.2 User: onlyoffice Pass: blalbla Port: 2343 ``` **Did this work in previous versions of DocumentServer?** have not tried yet **DocumentServer Docker tag:** 129a1d8ef76c **Host Operating System:** Distributor ID: Ubuntu Description: Ubuntu 18.04.3 LTS Release: 18.04 Codename: bionic
kerem 2026-02-26 09:36:36 +03:00
Author
Owner

@ShockwaveNN commented on GitHub (Jan 20, 2020):

I can confirm some trouble
Running docker run -it -e AMQP_SERVER_URL="amqp://onlyoffice:blalbla@10.0.0.2" onlyoffice/documentserver cause:

/app/ds/run-document-server.sh: line 360: [: !=: unary operator expected
 * Starting PostgreSQL 9.5 database server                                                                                                 [ OK ] 
 * Starting RabbitMQ Messaging Server rabbitmq-server                                                                                      [ OK ] 
Starting redis-server: redis-server.
invalid port 
Waiting for connection to the 10002 host on port

But with port everything is parsed fine (I didn't check if it really worked, just logs)

docker run -it -e AMQP_SERVER_URL="amqp://onlyoffice:blalbla@10.0.0.2:5556" onlyoffice/documentserver
 * Starting PostgreSQL 9.5 database server                                                                                                 [ OK ] 
Starting redis-server: redis-server.
Waiting for connection to the 10.0.0.2 host on port 5556
<!-- gh-comment-id:576254591 --> @ShockwaveNN commented on GitHub (Jan 20, 2020): I can confirm some trouble Running `docker run -it -e AMQP_SERVER_URL="amqp://onlyoffice:blalbla@10.0.0.2" onlyoffice/documentserver` cause: ``` /app/ds/run-document-server.sh: line 360: [: !=: unary operator expected * Starting PostgreSQL 9.5 database server [ OK ] * Starting RabbitMQ Messaging Server rabbitmq-server [ OK ] Starting redis-server: redis-server. invalid port Waiting for connection to the 10002 host on port ``` But with port everything is parsed fine (I didn't check if it really worked, just logs) ``` docker run -it -e AMQP_SERVER_URL="amqp://onlyoffice:blalbla@10.0.0.2:5556" onlyoffice/documentserver * Starting PostgreSQL 9.5 database server [ OK ] Starting redis-server: redis-server. Waiting for connection to the 10.0.0.2 host on port 5556 ```
Author
Owner

@ShockwaveNN commented on GitHub (Jan 20, 2020):

And accroding to https://www.rabbitmq.com/uri-spec.html port is optional

<!-- gh-comment-id:576255036 --> @ShockwaveNN commented on GitHub (Jan 20, 2020): And accroding to https://www.rabbitmq.com/uri-spec.html port is optional
Author
Owner

@ShockwaveNN commented on GitHub (Jan 20, 2020):

Seems problem actual only if host is ip (digits), if host is specified by host name - script is fine:

docker run -it -e AMQP_SERVER_URL="amqp://onlyoffice:blalbla@myserver" onlyoffice/documentserver
 * Starting PostgreSQL 9.5 database server                                                                                                 [ OK ] 
Starting redis-server: redis-server.
myserver: forward host lookup failed: Unknown host
Waiting for connection to the myserver host on port 5672
<!-- gh-comment-id:576270963 --> @ShockwaveNN commented on GitHub (Jan 20, 2020): Seems problem actual only if host is ip (digits), if host is specified by host name - script is fine: ``` docker run -it -e AMQP_SERVER_URL="amqp://onlyoffice:blalbla@myserver" onlyoffice/documentserver * Starting PostgreSQL 9.5 database server [ OK ] Starting redis-server: redis-server. myserver: forward host lookup failed: Unknown host Waiting for connection to the myserver host on port 5672 ```
Author
Owner

@liske commented on GitHub (Oct 7, 2022):

I have the same issue. The AMQP_URI parsing hack inside the entrypoint script seems to fail with ipv6 addresses, too.

<!-- gh-comment-id:1271240293 --> @liske commented on GitHub (Oct 7, 2022): I have the same issue. The AMQP_URI parsing hack inside the entrypoint script seems to fail with ipv6 addresses, too.
Author
Owner

@ShockwaveNN commented on GitHub (Oct 24, 2022):

Thanks for remembering, seems our developers have no free time to fix them, but I'll remind them

I've created issue 59483 in our private issue tracker to discuss this problem

<!-- gh-comment-id:1288966875 --> @ShockwaveNN commented on GitHub (Oct 24, 2022): Thanks for remembering, seems our developers have no free time to fix them, but I'll remind them I've created issue 59483 in our private issue tracker to discuss this problem
Author
Owner

@igwyd commented on GitHub (Dec 2, 2022):

Hello @Deltachaos, it's fixed at: https://github.com/ONLYOFFICE/Docker-DocumentServer/pull/529 and will be released in the next release

<!-- gh-comment-id:1334857160 --> @igwyd commented on GitHub (Dec 2, 2022): Hello @Deltachaos, it's fixed at: https://github.com/ONLYOFFICE/Docker-DocumentServer/pull/529 and will be released in the next release
Author
Owner

@DenisDeeSign commented on GitHub (Dec 20, 2022):

DocumentServer v7.2.2 is released. This issue should be fixed.

<!-- gh-comment-id:1359365602 --> @DenisDeeSign commented on GitHub (Dec 20, 2022): DocumentServer v7.2.2 is released. This issue should be fixed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Docker-DocumentServer-ONLYOFFICE#116
No description provided.