Skip to content

Using dataplane API by uncommenting 'program api' and 'userlist haproxy-dataplaneapi' section of config causes crash #8

@JamesTGrant

Description

@JamesTGrant

Using dataplane API in versions from 3.0.4 onward causes crash.

Simple to replicate by uncommenting 'program api' and 'userlist haproxy-dataplaneapi' section of the example config (note the VERSION variable in the following link!)
(https://raw.githubusercontent.com/haproxytech/haproxy-docker-ubuntu/refs/tags/$VERSION/3.0/haproxy.cfg)
Not yet found a way to use the dataplane API in versions later than 3.0.3

working in 3.0.3-95a607c
broken in 3.0.4-7a59afa onward

Uncomment these two lines from the haproxy.cfg:

program api
    command /usr/bin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /usr/local/etc/haproxy/haproxy.cfg --reload-cmd "kill -SIGUSR2 1" --restart-cmd "kill -SIGUSR2 1" --reload-delay 5 --userlist haproxy-dataplaneapi
    no option start-on-reload

userlist haproxy-dataplaneapi
  user admin insecure-password mypassword

log output:

[NOTICE]   (1) : New program 'api' (8) forked
[NOTICE]   (1) : New worker (9) forked
[NOTICE]   (1) : Loading success.
[WARNING]  (9) : Server static/static1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
2024/09/19 13:47:00 maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
2024/09/19 13:47:00 INFO memory is not limited, skipping package=github.com/KimMachineGun/automemlimit/memlimit
[WARNING]  (9) : Server static/static2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT]    (9) : backend 'static' has no server available!
configuration file /etc/haproxy/dataplaneapi.yaml does not exists, creating one
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb0 pc=0x101ce74]

goroutine 1 [running]:
github.com/haproxytech/dataplaneapi/configuration.(*Configuration).migrateUsers(0xc0003c3608)
        github.com/haproxytech/dataplaneapi/configuration/configuration_deprecated.go:76 +0xf4
github.com/haproxytech/dataplaneapi/configuration.(*Configuration).migrateDeprecatedFields(0xc0003c3608)
        github.com/haproxytech/dataplaneapi/configuration/configuration_deprecated.go:34 +0x12c
github.com/haproxytech/dataplaneapi/configuration.(*Configuration).LoadDataplaneStorageConfig(0xc0003c3608)
        github.com/haproxytech/dataplaneapi/configuration/configuration.go:312 +0x6c
main.startServer(0xc0003c3608, 0xc0003d8140)
        github.com/haproxytech/dataplaneapi/cmd/dataplaneapi/main.go:154 +0x985
main.main()
        github.com/haproxytech/dataplaneapi/cmd/dataplaneapi/main.go:67 +0x59
[NOTICE]   (1) : haproxy version is 3.0.4-7a59afa
[NOTICE]   (1) : path to executable is /usr/local/sbin/haproxy
[ALERT]    (1) : Current program 'api' (8) exited with code 2 (Exit)
[ALERT]    (1) : exit-on-failure: killing every processes with SIGTERM
[ALERT]    (1) : Current worker (9) exited with code 143 (Terminated)
[WARNING]  (1) : All workers exited. Exiting... (2)

Here is a BASH script to reproduce the issue:

#! /bin/bash

# fails with VERSION=3.0.4
# works with VERSION=3.0.3
VERSION=3.0.4

# remove any previous instances
if [ "$(docker ps -a -q -f name=my-running-haproxy)" ]; then
    docker stop my-running-haproxy
    docker rm my-running-haproxy
fi

mkdir -p /tmp/haproxy
rm -fR /tmp/haproxy/*
curl -k -L https://raw.githubusercontent.com/haproxytech/haproxy-docker-ubuntu/refs/tags/$VERSION/3.0/haproxy.cfg -o /tmp/haproxy/haproxy.cfg

dataplaneLines=$(cat <<EOF
 userlist haproxy-dataplaneapi
     user admin insecure-password mypassword

 program api
    command /usr/bin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /usr/local/etc/haproxy/haproxy.cfg --reload-cmd "kill -SIGUSR2 1" --restart-cmd "kill -SIGUSR2 1" --reload-delay 5 --userlist haproxy-dataplaneapi
    no option start-on-reload
EOF
)
printf "%s\n" "$dataplaneLines" >> /tmp/haproxy/haproxy.cfg

docker pull ghcr.io/haproxytech/haproxy-docker-ubuntu:$VERSION
docker run -d --name my-running-haproxy --expose 5555 -v /tmp/haproxy:/usr/local/etc/haproxy:rw haproxytech/haproxy-ubuntu:$VERSION
sleep 5
CONTAINER_ID=$(docker ps -a | grep haproxy | awk '{print $1}')
docker logs $CONTAINER_ID

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions