sonic-buildimage icon indicating copy to clipboard operation
sonic-buildimage copied to clipboard

Close rsyslog plugin when rsyslog SIGTERM and EOF is sent to stream

Open zbud-msft opened this issue 1 year ago • 1 comments

Why I did it

Work item tracking
  • Microsoft ADO (number only):27882794

How I did it

Add signalOnClose for omprog as well as close rsyslog plugin when receives an EOF.

How to verify it

UT (will add sonic-mgmt testcase for storming events with logs)

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

  • [ ] 201811
  • [ ] 201911
  • [ ] 202006
  • [ ] 202012
  • [ ] 202106
  • [ ] 202111
  • [ ] 202205
  • [ ] 202211
  • [ ] 202305

Tested branch (Please provide the tested image version)

  • [ ]
  • [ ]

Description for the changelog

Link to config_db schema for YANG module changes

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

zbud-msft avatar Apr 30 '24 16:04 zbud-msft

can you explain why?

lguohan avatar May 02 '24 04:05 lguohan

@zbud-msft could you please check why the checker is skipped? would you please re-trigger it?

keboliu avatar May 09 '24 02:05 keboliu

@lguohan This change is to address 2 issues

  1. When rsyslogd is terminated, no signal is sent to child process of rsyslog_plugin meaning that rsyslog_plugin will be constantly trying to read from cin with no writer on the other end of the pipe. This leads to rsyslog_plugin process will constantly be reading via getline infinitely.

  2. Because rsyslog is terminated and the spawned rsyslog_plugin is still alive, when rsyslog starts backup again, and log is triggered, a new rsyslog_plugin will be spawned for that rsyslog process, which can lead to many "ghost" rsyslog_plugin processes that will be at high CPU usage.

zbud-msft avatar May 15 '24 00:05 zbud-msft

Fixes https://github.com/sonic-net/sonic-buildimage/issues/18771

vivekrnv avatar May 15 '24 01:05 vivekrnv

Cherry-pick PR to 202311: https://github.com/sonic-net/sonic-buildimage/pull/18968

mssonicbld avatar May 15 '24 01:05 mssonicbld

Hi @zbud-msft, the change only handles SIG_TERM, but EOF of pipe is not handled yet. If rsyslog is killed by SIG_KILL or crash unexpectedly, the busy look is still there.

bingwang-ms avatar Jun 06 '24 18:06 bingwang-ms

Discussed with Bing offline. From the code we are handling EOF. In loop we are checking getline(cin, line). If EOF is sent, getline(cin, line) will evaluate to false. UT also shows that we are replacing cin buffer with empty input stream, which will be treated as EOF when getline() is called by plugin->run.

zbud-msft avatar Jun 06 '24 20:06 zbud-msft