Skip to content

Conversation

@spaceone
Copy link
Member

The following script demonstrates a KeyError which is caused if a socket which currently has some pending input/output was removed in a notifier timer.
The problem is that step() first poll()s, then executes the timers() and then uses the polled FD's.

$ cat timer_bug.py
import notifier
import subprocess
notifier.init()

fd = None
def on_read(sock):
        print 'on_read'
        return True
def on_timer():
        print 'on_timer'
        notifier.socket_remove(fd)
        return True
p = subprocess.Popen('python -c "import sys; sys.stdin.read()"', shell=True, stdin=subprocess.PIPE)
fd = p.stdin.fileno()
notifier.socket_add(fd, on_read)
notifier.timer_add(0, on_timer)
p.communicate('A')
notifier.step()

$ python timer_bug.py
on_timer
Traceback (most recent call last):
  File "timer_bug.py", line 18, in <module>
    notifier.step()
  File "/home/git/python-notifier/notifier/nf_generic.py", line 259, in step
    sock_obj = __sock_objects[ fd ]
KeyError: 4

The following script demonstrates a KeyError which is caused if a socket which currently has some pending input/output was removed in a notifier timer.
The problem is that step() first poll()s, then executes the timers() and then uses the polled FD's.

$ cat timer_bug.py
import notifier
import subprocess
notifier.init()

fd = None
def on_read(sock):
        print 'on_read'
        return True
def on_timer():
        print 'on_timer'
        notifier.socket_remove(fd)
        return True
p = subprocess.Popen('python -c "import sys; sys.stdin.read()"', shell=True, stdin=subprocess.PIPE)
fd = p.stdin.fileno()
notifier.socket_add(fd, on_read)
notifier.timer_add(0, on_timer)
p.communicate('A')
notifier.step()

$ python timer_bug.py
on_timer
Traceback (most recent call last):
  File "timer_bug.py", line 18, in <module>
    notifier.step()
  File "/home/git/python-notifier/notifier/nf_generic.py", line 259, in step
    sock_obj = __sock_objects[ fd ]
KeyError: 4
@crunchy-github crunchy-github merged commit 6446977 into univention:master Jun 10, 2017
@crunchy-github
Copy link
Contributor

merged

@spaceone spaceone deleted the step_timer_keyerror branch June 16, 2017 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants