mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
Prevent overfilling of self-pipe in python event loop
If the event loop takes a very long time todo something, it is possible for the 'self pipe' buffer to become full at which point the entire event loop + remote driver deadlock. Use a boolean flag to ensure we have strict one-in, one-out behaviour on writes/reads of the 'self pipe'
This commit is contained in:
parent
cc4447b68a
commit
331d7b09a7
@ -92,6 +92,8 @@ class virEventLoopPure:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.poll = select.poll()
|
self.poll = select.poll()
|
||||||
self.pipetrick = os.pipe()
|
self.pipetrick = os.pipe()
|
||||||
|
self.pendingWakeup = False
|
||||||
|
self.runningPoll = False
|
||||||
self.nextHandleID = 1
|
self.nextHandleID = 1
|
||||||
self.nextTimerID = 1
|
self.nextTimerID = 1
|
||||||
self.handles = []
|
self.handles = []
|
||||||
@ -166,6 +168,7 @@ class virEventLoopPure:
|
|||||||
# these pointless repeated tiny sleeps.
|
# these pointless repeated tiny sleeps.
|
||||||
def run_once(self):
|
def run_once(self):
|
||||||
sleep = -1
|
sleep = -1
|
||||||
|
self.runningPoll = True
|
||||||
next = self.next_timeout()
|
next = self.next_timeout()
|
||||||
debug("Next timeout due at %d" % next)
|
debug("Next timeout due at %d" % next)
|
||||||
if next > 0:
|
if next > 0:
|
||||||
@ -184,6 +187,7 @@ class virEventLoopPure:
|
|||||||
# telling us to wakup. if so, then discard
|
# telling us to wakup. if so, then discard
|
||||||
# the data just continue
|
# the data just continue
|
||||||
if fd == self.pipetrick[0]:
|
if fd == self.pipetrick[0]:
|
||||||
|
self.pendingWakeup = False
|
||||||
data = os.read(fd, 1)
|
data = os.read(fd, 1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -206,6 +210,8 @@ class virEventLoopPure:
|
|||||||
t.set_last_fired(now)
|
t.set_last_fired(now)
|
||||||
t.dispatch()
|
t.dispatch()
|
||||||
|
|
||||||
|
self.runningPoll = False
|
||||||
|
|
||||||
|
|
||||||
# Actually the event loop forever
|
# Actually the event loop forever
|
||||||
def run_loop(self):
|
def run_loop(self):
|
||||||
@ -214,6 +220,8 @@ class virEventLoopPure:
|
|||||||
self.run_once()
|
self.run_once()
|
||||||
|
|
||||||
def interrupt(self):
|
def interrupt(self):
|
||||||
|
if self.runningPoll and not self.pendingWakeup:
|
||||||
|
self.pendingWakeup = True
|
||||||
os.write(self.pipetrick[1], 'c')
|
os.write(self.pipetrick[1], 'c')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user