Skip to content

[swss.sh/syncd.sh] Trap only on EXIT#11590

Merged
yxieca merged 1 commit intosonic-net:masterfrom
stepanblyschak:trap-exit-fix
Aug 11, 2022
Merged

[swss.sh/syncd.sh] Trap only on EXIT#11590
yxieca merged 1 commit intosonic-net:masterfrom
stepanblyschak:trap-exit-fix

Conversation

@stepanblyschak
Copy link
Collaborator

When using trap on SIGTERM the script will not react to the SIGTERM signal sent while a child is executing.
I.e, the following script does not react on SIGTERM sent to it if it is
waiting for sleep to finish:

#!/bin/bash
trap "echo Handled SIGTERM" 0 2 3 15

echo "Before sleep"
sleep inf
echo "After sleep"

On SIGTERM sent to the followig script:

+ trap 'echo Handled SIGTERM' 15
+ echo Before sleep
Before sleep
+ sleep inf

Terminated
++ echo Handled SIGTERM
Handled SIGTERM
+ echo After sleep
After sleep

"echo After sleep" shouldn't be printed, the script has to exit.

Instead, trap only on EXIT which covers also a scenario with exit on
SIGINT, SIGTERM.

Signed-off-by: Stepan Blyschak stepanb@nvidia.com

Why I did it

When NVIDIA switch is first booting FW upgrade process starts, if user does ztp disable -y during that process, which calls config reload -y -f all services will be terminated, including syncd and running FW upgrade process, however, it is observed that syncd.sh does not terminate but continues loading kernel drivers. This will cause an issue on next syncd start leading to switch init failure.

How I did it

Changed the signal for trap.

How to verify it

Boot NVIDIA switch first time, do "ztp disable -y", verify after some time all services are started and running.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

When using trap on SIGTERM the script will not react to the SIGTERM signal sent while a child is executing.
I.e, the following script does not react on SIGTERM sent to it if it is
waiting for sleep to finish:

```

trap "echo Handled SIGTERM" 0 2 3 15

echo "Before sleep"
sleep inf
echo "After sleep"
```

Instead, trap only on EXIT which covers also a scenario with exit on
SIGINT, SIGTERM.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
@stepanblyschak stepanblyschak requested a review from lguohan as a code owner August 1, 2022 08:35
@liat-grozovik
Copy link
Collaborator

@prsunny could you please help to review or assing someone?

@liat-grozovik
Copy link
Collaborator

/easycla

@liat-grozovik
Copy link
Collaborator

@yxieca , @prsunny please help to review.
i added label only to the main supported branches. this is the prio. it can be taken to other branches as well as needed.

@yxieca yxieca merged commit 2d42993 into sonic-net:master Aug 11, 2022
yxieca pushed a commit that referenced this pull request Aug 11, 2022
When using trap on SIGTERM the script will not react to the SIGTERM signal sent while a child is executing.
I.e, the following script does not react on SIGTERM sent to it if it is
waiting for sleep to finish:

```

trap "echo Handled SIGTERM" 0 2 3 15

echo "Before sleep"
sleep inf
echo "After sleep"
```

Instead, trap only on EXIT which covers also a scenario with exit on
SIGINT, SIGTERM.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
qiluo-msft pushed a commit that referenced this pull request Aug 11, 2022
When using trap on SIGTERM the script will not react to the SIGTERM signal sent while a child is executing.
I.e, the following script does not react on SIGTERM sent to it if it is
waiting for sleep to finish:

```

trap "echo Handled SIGTERM" 0 2 3 15

echo "Before sleep"
sleep inf
echo "After sleep"
```

Instead, trap only on EXIT which covers also a scenario with exit on
SIGINT, SIGTERM.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
skbarista pushed a commit to skbarista/sonic-buildimage that referenced this pull request Aug 17, 2022
When using trap on SIGTERM the script will not react to the SIGTERM signal sent while a child is executing.
I.e, the following script does not react on SIGTERM sent to it if it is
waiting for sleep to finish:

```

trap "echo Handled SIGTERM" 0 2 3 15

echo "Before sleep"
sleep inf
echo "After sleep"
```

Instead, trap only on EXIT which covers also a scenario with exit on
SIGINT, SIGTERM.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants