unstack.sh leaves the terminal garbled

Bug #1999395 reported by Bence Romsics
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
devstack
Fix Released
Low
Bence Romsics

Bug Description

For some time (I did not record when this started) unstack.sh leaves my terminal garbled. In the middle of its run, carriage returns become broken. After it completes, terminal echo is off. Here's unstack.sh output where it gets garbled (I hope launchpad keeps the whitespace so the problem can be seen):

+functions-common:is_service_enabled:2050 xtrace='set -o xtrace' +functions-common:is_service_enabled:2051 set +o xtrace
+functions-common:is_service_enabled:2078 return 1
+lib/neutron-legacy:stop_mutnauq_other:638 [[ True == \T\r\u\e ]]
+lib/neutron-legacy:stop_mutnauq_other:639 sudo pkill -9 -f /usr/local/bin/neutron-rootwrap-daemon
/home/rubasov/src/os/openstack/devstack/lib/neutron-legacy: line 611: 278731 Killed sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon
                                                                                                                                              +lib/neutron-legacy:stop_mutnauq_other:639 :
                                                                                                                                                                                           +lib/neutron-legacy:stop_mutnauq:646 stop_mutnauq_l2_agent

Clearly it gets broken by this line:
https://opendev.org/openstack/devstack/src/commit/9a1be7794bd3b1b06a89183a800f42f77cd1b1b9/lib/neutron-legacy#L639

The bug remains present even if I replace that line with:
sudo pkill -9 -f no-such-process || :

This gave me the hunch that pkill may be killing itself. However "man 1 pkill" claims:
"The running pgrep, pkill, or pidwait process will never report itself as a match."

After turning on process accounting, I realized that "sudo pkill" does not kill the "pkill" process but the "sudo" process:

$ sudo apt install acct
$ sudo accton on
$ unstack.sh
...
+lib/neutron-legacy:stop_mutnauq_other:639 sudo pkill -9 -f no-such-process
/home/rubasov/src/os/openstack/devstack/lib/neutron-legacy: line 611: 336085 Killed sudo pkill -9 -f no-such-process
...
$ sudo dump-acct /var/log/account/pacct | egrep 336085
sudo |v3| 0.00| 0.00| 0.00| 1000| 0| 14416.00| 0.00| 336085| 331695|S X| 0|pts/1 |Mon Dec 12 11:04:55 2022

Clearly "pkill -f" is needed for this bug to happen. And it seems to me that sending the KILL/9 signal is also necessary.
Therefore this probably affects all occurrences of "sudo pkill -9 -f". I found two, here's the other one:

https://opendev.org/openstack/devstack/src/commit/9a1be7794bd3b1b06a89183a800f42f77cd1b1b9/lib/neutron_plugins/ovn_agent#L771

There are still multiple pieces I do not understand:
* A standalone "sudo pkill -9 -f" is not enough to reproduce the bug (or to kill sudo).
* How killing sudo leaves the terminal garbled.

But at this point I can propose a fix, which I will upload soon.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to devstack (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/devstack/+/867215

Changed in devstack:
status: New → In Progress
Changed in devstack:
assignee: nobody → Bence Romsics (bence-romsics)
Revision history for this message
Dr. Jens Harbott (j-harbott) wrote :

The sudo command seems to change tty settings. You can use "stty sane" as a workaround to restore normal tty behavior. Still good to fix this properly.

Changed in devstack:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to devstack (master)

Reviewed: https://review.opendev.org/c/openstack/devstack/+/867215
Committed: https://opendev.org/openstack/devstack/commit/71c3c40c269a50303247855319d1d3a5d30f6773
Submitter: "Zuul (22348)"
Branch: master

commit 71c3c40c269a50303247855319d1d3a5d30f6773
Author: Bence Romsics <email address hidden>
Date: Wed Dec 21 13:50:54 2022 +0100

    'sudo pkill -f' should not match the sudo process

    pkill already takes care that it does not kill itself, however the
    same problem may happen with 'sudo pkill -f' killing sudo. Use one
    of the usual regex tricks to avoid that.

    Change-Id: Ic6a94f516cbc509a2d77699494aa7bcaecf96ebc
    Closes-Bug: #1999395

Changed in devstack:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.