Skip to content

GPIO library doesn't free GPIO file descriptor. File descriptor leak. #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Red-Eyed opened this issue Jun 25, 2017 · 1 comment
Closed

Comments

@Red-Eyed
Copy link
Contributor

Hello, I found such issue.
I got example of LED and run it.
LED are blink for about minute and that's all.
I run strace and found such error:

select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr0/brightness", O_WRONLY) = 1023
open("/sys/class/leds/beaglebone:green:usr0/brightness", O_WRONLY) = -1 EMFILE (Too many open files)
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr1/brightness", O_WRONLY) = -1 EMFILE (Too many open files)
open("/sys/class/leds/beaglebone:green:mmc0/brightness", O_WRONLY) = -1 EMFILE (Too many open files)
  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.):
platform.platform()
'Linux-3.8.13-bone79-armv7l-with-debian-7.11'
platform.linux_distribution()
('debian', '7.11', '')
  • Python version (run python -version or python3 -version):
platform.python_version()
'2.7.3'

  • Error message you are receiving, including any Python exception traces:
    Library doesn't emit any messages. I did strace.
    Here strace logs:
root@beaglebone:/home/debian# strace -f python programs/beaglebone-test.py
...
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr2/brightness", O_WRONLY) = 9
open("/sys/class/leds/beaglebone:green:usr2/brightness", O_WRONLY) = 10
write(10, "1", 1)                       = 1
close(10)                               = 0
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr3/brightness", O_WRONLY) = 10
open("/sys/class/leds/beaglebone:green:usr3/brightness", O_WRONLY) = 11
write(11, "1", 1)                       = 1
close(11)                               = 0
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr0/brightness", O_WRONLY) = 11
open("/sys/class/leds/beaglebone:green:usr0/brightness", O_WRONLY) = 12
write(12, "0", 1)                       = 1
close(12)                               = 0
...
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr2/brightness", O_WRONLY) = 1021
open("/sys/class/leds/beaglebone:green:usr2/brightness", O_WRONLY) = 1022
write(1022, "0", 1)                     = 1
close(1022)                             = 0
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr3/brightness", O_WRONLY) = 1022
open("/sys/class/leds/beaglebone:green:usr3/brightness", O_WRONLY) = 1023
write(1023, "0", 1)                     = 1
close(1023)                             = 0
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr0/brightness", O_WRONLY) = 1023
open("/sys/class/leds/beaglebone:green:usr0/brightness", O_WRONLY) = -1 EMFILE (Too many open files)
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
open("/sys/class/leds/beaglebone:green:usr1/brightness", O_WRONLY) = -1 EMFILE (Too many open files)
open("/sys/class/leds/beaglebone:green:mmc0/brightness", O_WRONLY) = -1 EMFILE (Too many open files)
select(0, NULL, NULL, NULL, {0, 100000}) = 0 (Timeout)
...
and so on
  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
    On BeagleBone with debian 7 run as root the "On-Board LEDs" example with sleep(0.1) and
    wait several minutes. Then you will see that LEDs stop blinking, and program doesn't emit any error.
    To get error logs:
    Code:
# beaglebone-test.py
import Adafruit_BBIO.GPIO as GPIO
import time

if __name__=="__main__":
    for i in range(4):
        GPIO.setup("USR%d" % i, GPIO.OUT)

    while True:
        for i in range(4):
            GPIO.output("USR%d" % i, GPIO.HIGH)
            time.sleep(0.1)
        for i in range(4):
            GPIO.output("USR%d" % i, GPIO.LOW)
            time.sleep(0.1)

Run script:
strace -f python programs/beaglebone-test.py

@Red-Eyed Red-Eyed changed the title GPIO library doesn't free GPIO file descriptor GPIO library doesn't free GPIO file descriptor. File descripto leak. Jun 25, 2017
@Red-Eyed Red-Eyed changed the title GPIO library doesn't free GPIO file descriptor. File descripto leak. GPIO library doesn't free GPIO file descriptor. File descriptor leak. Jun 25, 2017
Red-Eyed added a commit to Red-Eyed/adafruit-beaglebone-io-python that referenced this issue Jun 25, 2017
…or. File descriptor leak.

Made a little bit refactoring
pdp7 added a commit that referenced this issue Jun 27, 2017
Fixed issue #145 GPIO library doesn't free GPIO file descriptor. File descriptor leak.
@pdp7
Copy link
Collaborator

pdp7 commented Jun 27, 2017

resolved by #146. thanks @Vadim-Stupakov

@pdp7 pdp7 closed this as completed Jun 27, 2017
pdp7 added a commit that referenced this issue Aug 23, 2017
Version 1.0.4: bug fixes and enhancements from last 6 months

- @djsutton (1):
  - fix TypeError: function takes exactly 3 arguments (2 given) from wait_for_edge

- @pdp7 (29):
  - Instruct users to open GitHub issue instead email
  - add udev rules and script for non-root access to gpio
  - fix file descriptor leak in gpio_set_value()
  - document how to test read and write to all GPIO pins
  - reduce ADC reads in pytest from 10,000 to 1,000
  - close file descriptor to avoid leak
  - remove conditional logic for ctrl_dir and ocp_dir size
  - increase size of ctrl_dir and ocp_dir for future use
  - Document how to run config-pin at boot
  - Document how to test eQEP with Rotary Encoder
  - Add skeleton for Encoder module to read eQEP
  - Add code to Encoder.QEP from PyBBIO.RotaryEncoder
  - Adapt code from PyBBIO.RotaryEncoder
  - add test for rotary encoder
  - read from eqep position file
  - return position from getPosition()
  - document howo to enable all the eqep pins
  - Document how to test eqep pins with rotary encoder
  - run config-pin to set pin mux for qep
  - update QEP test
  - update QEP test for issue #122
  - Test if kernel booted wit u-boot overlays
  - check if kernel cmdline for uboot overlay
  - Add documentation about u-boot overlays
  - Return BBIO_OK when u-boot overlays ared enabled
  - remove debug printing
  - Skip check for device tree loaded if u-boot overlays enabled
  - Sleep after loading ADC overlay to allow driver load
  - Workaround test failure until TIMERn bug is fixed

- @ltjax (3):
  - Use lookup table to prevent duplicate pin export
  - Handle already exported pins
  - Fix build_path memory leak

- @Vadim-Stupakov (1):
  - Fixed issue #145 GPIO library doesn't free GPIO file descriptor. File descriptor leak.     Made a little bit refactoring

- @cocasema (8):
  - Declare PHONY targets in root Makefile
  - Extract BBIO_err into a separate header
  - Add syslog and debugging messages
  - Add libadafruit-bbio with C++ wrappers for PWM/GPIO
  - Add 2 versions of library with c++98 and c++11 abi
  - Install header files properly
  - Add default values to pwm::start() method.
  - Add PWM c++ tests

- @zsserg (2):
  - Added error checking for setting pin direction in gpio.setup() (Python)
  - Added debug output to set_pin_mode()
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

No branches or pull requests

2 participants