Skip to content

Race condition when executing lldpcli in parallel #343

@wataash

Description

@wataash

Executing

  • lldpcli -ddddd configure system hostname foo
  • lldpcli -ddddd configure system description bar

in parallel may results in:

  • hostname: (none) (foo expected)
  • description: bar
$ lldpcli configure system hostname foo & lldpcli configure system description bar
$ lldpcli show configuration
-------------------------------------------------------------------------------
Global configuration:
-------------------------------------------------------------------------------
Configuration:
  Transmit delay: 30
  ...
  Override description with: bar
                             ^^^ OK
  Override platform with: Darwin
  Override system name with: (none)
                             ^^^^^^ expected foo
  Advertise version: yes
  ...
-------------------------------------------------------------------------------

Here's a sequence diagram (generated with PlantUML) explaining what happened:

image

To reproduce this easily, I patched the following diff:

diff --git a/src/daemon/event.c b/src/daemon/event.c
index c42bc3fa..998807b9 100644
--- a/src/daemon/event.c
+++ b/src/daemon/event.c
@@ -330,6 +330,8 @@ levent_ctl_recv(struct bufferevent *bev, void *ptr)
        void *data = NULL;

        log_debug("control", "receive data on Unix socket");
+       log_debug("control", "sleep(5)");
+       sleep(5);
        if (buffer_len < sizeof(struct hmsg_header))
                return;         /* Not enough data yet */
        if (evbuffer_copyout(buffer, &hdr,

Log from lldpd -ddddd:

$ lldpd -ddddd

$ lldpcli configure system hostname foo

handle GET_CONFIG from lldpcli 1 (hostname foo)

2019-09-04T13:09:31 [ DBG/control] accept a new connection
2019-09-04T13:09:31 [ DBG/event] new client accepted
2019-09-04T13:09:31 [ DBG/control] receive data on Unix socket
2019-09-04T13:09:31 [ DBG/control] sleep(5)

$ lldpcli configure system description bar

2019-09-04T13:09:36 [ DBG/rpc] handle client request
2019-09-04T13:09:36 [ DBG/rpc] client requested configuration
2019-09-04T13:09:36 [ DBG/marshal] start serialization of lldpd_config
2019-09-04T13:09:36 [ DBG/marshal] start serialization of null string

handle GET_CONFIG from lldpcli 2 (description bar)

2019-09-04T13:09:36 [ DBG/control] accept a new connection
2019-09-04T13:09:36 [ DBG/event] new client accepted
2019-09-04T13:09:36 [ DBG/control] receive data on Unix socket
2019-09-04T13:09:36 [ DBG/control] sleep(5)
2019-09-04T13:09:41 [ DBG/rpc] handle client request
2019-09-04T13:09:41 [ DBG/rpc] client requested configuration
2019-09-04T13:09:41 [ DBG/marshal] start serialization of lldpd_config
2019-09-04T13:09:41 [ DBG/marshal] start serialization of null string

handle SET_CONFIG from lldpcli 1 (hostname foo)

2019-09-04T13:09:41 [ DBG/control] receive data on Unix socket
2019-09-04T13:09:41 [ DBG/control] sleep(5)
2019-09-04T13:09:46 [ DBG/rpc] handle client request
2019-09-04T13:09:46 [ DBG/rpc] client request a change in configuration
2019-09-04T13:09:46 [ DBG/marshal] start unserialization of lldpd_config
2019-09-04T13:09:46 [ DBG/marshal] start unserialization of null string
2019-09-04T13:09:46 [ DBG/marshal] start unserialization of null string
2019-09-04T13:09:46 [ DBG/rpc] change system name to foo
2019-09-04T13:09:46 [ DBG/localchassis] update information for local chassis
2019-09-04T13:09:46 [ DBG/localchassis] use overridden system name `foo`
2019-09-04T13:09:46 [ DBG/localchassis] advertise system version
2019-09-04T13:09:46 [ DBG/alloc] general configuration cleanup
2019-09-04T13:09:46 [ DBG/loop] start new loop
2019-09-04T13:09:46 [ DBG/loop] update information for local ports
2019-09-04T13:09:46 [ DBG/localchassis] update information for local ports
2019-09-04T13:09:46 [ DBG/interfaces] grabbing information on interface lo0
...
2019-09-04T13:09:46 [ DBG/localchassis] update information for local chassis
2019-09-04T13:09:46 [ DBG/localchassis] use overridden system name `foo`
2019-09-04T13:09:46 [ DBG/localchassis] advertise system version

handle SET_CONFIG from lldpcli 2 (description bar)

2019-09-04T13:09:46 [ DBG/control] receive data on Unix socket
2019-09-04T13:09:46 [ DBG/control] sleep(5)
2019-09-04T13:09:51 [ DBG/rpc] handle client request
2019-09-04T13:09:51 [ DBG/rpc] client request a change in configuration
2019-09-04T13:09:51 [ DBG/marshal] start unserialization of lldpd_config
2019-09-04T13:09:51 [ DBG/marshal] start unserialization of null string
2019-09-04T13:09:51 [ DBG/marshal] start unserialization of null string
2019-09-04T13:09:51 [ DBG/rpc] change chassis description to bar
2019-09-04T13:09:51 [ DBG/localchassis] update information for local chassis
2019-09-04T13:09:51 [ DBG/localchassis] use overridden system name `foo`
2019-09-04T13:09:51 [ DBG/localchassis] use overridden description `bar`
2019-09-04T13:09:51 [ DBG/rpc] change system name to (NULL)
2019-09-04T13:09:51 [ DBG/localchassis] update information for local chassis
2019-09-04T13:09:51 [ DBG/privsep] received command 2
2019-09-04T13:09:51 [ DBG/localchassis] use overridden description `bar`
2019-09-04T13:09:51 [ DBG/alloc] general configuration cleanup
2019-09-04T13:09:51 [ DBG/loop] start new loop
2019-09-04T13:09:51 [ DBG/loop] update information for local ports
2019-09-04T13:09:51 [ DBG/localchassis] update information for local ports
...
2019-09-04T13:09:51 [ DBG/localchassis] update information for local chassis
2019-09-04T13:09:51 [ DBG/privsep] received command 2
2019-09-04T13:09:51 [ DBG/localchassis] use overridden description `bar`
2019-09-04T13:09:51 [ DBG/event] client has been disconnected
2019-09-04T13:09:51 [ DBG/event] trigger sending PDU for port en0
2019-09-04T13:09:51 [ DBG/send] send PDU on en0
2019-09-04T13:09:51 [ DBG/send] fallback to protocol LLDP for en0
2019-09-04T13:09:51 [ DBG/lldp] send LLDP PDU to en0
2019-09-04T13:09:51 [ DBG/interfaces] send PDU to ethernet device en0 (fd=8)
2019-09-04T13:09:51 [ DBG/event] trigger sending PDU for port en1
2019-09-04T13:09:51 [ DBG/event] client has been disconnected

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