Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 11, 2022

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>
@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