Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1525171

Summary: Ensure that only one VDSM instance is running
Product: [oVirt] vdsm Reporter: Nir Soffer <nsoffer>
Component: CoreAssignee: Yaniv Bronhaim <ybronhei>
Status: CLOSED CURRENTRELEASE QA Contact: Pavol Brilla <pbrilla>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.20.15CC: bugs, danken, ebenahar, mperina, nsoffer, ybronhei
Target Milestone: ovirt-4.2.2Flags: rule-engine: ovirt-4.2+
Target Release: 4.20.19   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: v4.20.19 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-03-29 11:07:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Nir Soffer 2017-12-12 17:25:57 UTC
Description of problem:

Vdsm assumes that systemd is ensuring that only once instance is running. However 
if vdsm is in D state when restarted, systemd will ignore the kill failure, 
and try to start the service twice (actually infinite times). This fails because
vdsm is still listening on the vdsm socket, but we cannot rely on this.

Vdsm needs to keep a lockfile in /var/lock, to ensure that only one instance
is running, regardless of systemd behavior or bugs.

The first thing vdsm should do after configuring logging is acquiring the lock
file with a timeout of 0 seconds. If the lock is held by another process, vdsm
should exit with a clear error.

Version-Release number of selected component (if applicable):
Since ovirt 4.0 or rhel 7.

How reproducible:
Always

Steps to Reproduce:
1. Cause vdsm to be in D state by blocking access to storage with NFS storage
2. Restart vdsm service

Actual results:
Systemd goes into restart loop, starting the service again and again.
We can see that new processes are started before the old process terminated.
The new proceses writes few lines to vdsm log for every run, then fail 
with the excpetion "Address in use"

Expected results:
Vdsm fails immediately on startup with a clear error about another running
instance.

Comment 1 Yaniv Bronhaim 2017-12-13 12:43:40 UTC
Nir, it sounds a regression, maybe related to subprocess32 usage?  Can you verify that this is not behavior change? NFS storage access happens in external process afaik, once vdsmd dies, this child process is taken care of by systemd.
we used to use lock file before using systemd services - and after moving to systemd we never needed to take care for being zombies

Comment 2 Nir Soffer 2017-12-13 16:29:04 UTC
(In reply to Yaniv Bronhaim from comment #1)
> Nir, it sounds a regression, maybe related to subprocess32 usage?  

No, we see it in 4.1, using cpopen. Please check this, explaning the issue:
https://bugzilla.redhat.com/show_bug.cgi?id=1518676#c25

I will file a systemd bug about restarting service after kill fail to terminate
it, but I think we should take care of this regardless of systemd.

> Can you
> verify that this is not behavior change? NFS storage access happens in
> external process afaik, 

We still have code accessing NFS directly, we are in the process of removing this
code.

> once vdsmd dies, this child process is taken care of
> by systemd.
> we used to use lock file before using systemd services - and after moving to
> systemd we never needed to take care for being zombies

This is not about zombies, but about process hang in D state. Killing it does
nothing since the process is uninterruptible.

Comment 3 Yaniv Bronhaim 2017-12-14 12:39:58 UTC
ok, so avoiding accessing IO that can be unreachable in main process is the solution for such cases? we should use ioprocess for those accesses.. otherwise we can't really escape from the D state when setting reaching unreachable nfs address, no?

Comment 4 Yaniv Bronhaim 2017-12-20 21:14:38 UTC
This bug is about adding flock mechanism to prevent running vdsmd instance again - https://gerrit.ovirt.org/85665

Comment 5 Dan Kenigsberg 2017-12-25 05:39:41 UTC
I think that systemd should take care of this. Do we have a matching bug there?

Comment 6 Yaniv Bronhaim 2018-01-03 10:45:19 UTC
Bug #1530556 is about running new instance although systemd failed to kill original service pid. I didn't set it as Blocks\Depends on for this bug, as in this bugzilla the expected result is that vdsmd will fail immediately on startup with a clear error about another running instance.

Comment 7 Yaniv Bronhaim 2018-01-03 14:27:55 UTC
Adding the bug dependency. the fix is more as workaround for vdsmd more than actually solving the bug in systemd

Comment 8 Yaniv Bronhaim 2018-01-08 14:49:57 UTC
Using lock file doesn't help. Actually all fds of the origin process are removed once sigkill sent by systemd. This means that another instance can start normally and the original pid stacks until storage is reachable again.

Comment 9 Martin Perina 2018-02-15 13:31:44 UTC
Moving back to POST, patch is not included in ovirt-4.2 branch

Comment 10 Avihai 2018-02-19 08:14:16 UTC
Verification blocked due to Bug 1530556 which is in "NEW" state .

Comment 11 Yaniv Bronhaim 2018-02-19 09:28:08 UTC
putting Bug 1530556 as "depends on" is wrong. It's additional bug that its fix can make the fix we do here redundant. It doesn't block the verification for running vdsmd process twice. start vdsmd service, change to vdsm user and run "/usr/share/vdsm/vdsmd" again. /var/lib/vdsm/vdsmd.lock file should lock the second process and fail the run

Comment 14 Pavol Brilla 2018-03-07 09:23:53 UTC
On host running vdsm
vdsm-4.20.20-1.el7ev.x86_64

2nd try to run vdsm - failed with nice error

# /usr/share/vdsm/vdsmd
Traceback (most recent call last):
File "/usr/share/vdsm/vdsmd", line 12, in <module>
  vdsmd.main()
File "/usr/lib/python2.7/site-packages/vdsm/vdsmd.py", line 268, in main
  __assertSingleInstance()
File "/usr/lib/python2.7/site-packages/vdsm/vdsmd.py", line 214, in __assertSingleInstance
    raise FatalError(str(e))
vdsm.vdsmd.FatalError: Instance already running

Lock file /run/vdsm/vdsmd.lock exists

Comment 15 Sandro Bonazzola 2018-03-29 11:07:14 UTC
This bugzilla is included in oVirt 4.2.2 release, published on March 28th 2018.

Since the problem described in this bug report should be
resolved in oVirt 4.2.2 release, it has been closed with a resolution of CURRENT RELEASE.

If the solution does not work for you, please open a new bug report.