Opened 5 years ago

Last modified 3 years ago

#4481 defect new

reference cycle involving glib2reactor causes gobject to leak file descriptors

Reported by: exarkun Owned by: itamar
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch: branches/glib2reactor-fd-leak-4481
(diff, github, buildbot, log)
Author: exarkun Launchpad Bug:

Description

Recent versions of pygobject use a pipe to ensure that threading is properly supported (or something like that). The pipe is closed when the MainLoop instance is freed. However, pygobject doesn't seem to handle reference cycles. glib2reactor creates a reference cycle from itself to a MainLoop instance back to the reactor (probably via its doIterationTimer and/or simulate method).

The problem thus created can be observed by using trial -u to run a unit test which creates and destroys a glib2reactor instance. Eventually enough pipes will leak such that no more can be created and the test run will fail. For example:

trial -u twisted.internet.test.test_tcp.TCPClientTestsBuilder_Glib2Reactor.test_addresses

fails after about 1021 iterations (using the versions of things packaged in Ubuntu 10.04).

This appears to be fixable by manually breaking the cycle.

Change History (4)

comment:1 Changed 5 years ago by exarkun

  • Author set to exarkun
  • Branch set to branches/glib2reactor-fd-leak-4481

(In [29171]) Branching to 'glib2reactor-fd-leak-4481'

comment:2 Changed 5 years ago by exarkun

(In [29246]) This might fix it on Lucid

refs #4481

comment:3 Changed 4 years ago by <automation>

  • Owner glyph deleted

comment:4 Changed 3 years ago by itamar

  • Owner set to itamar

In trunk (r33906) the suggested test run does fail after 1021 runs. However, /proc/<pid>/fd shows no fd leak, nor any file descriptors with numbers higher than 12. The error coming out of gobject is:

twisted/internet/_glibbase.py:310: Warning: poll(2) failed due to: Invalid argument.

Note: See TracTickets for help on using tickets.