Skip to content

Fix "too many open files" error during track transfer to device

crvi requested to merge crvi/rhythmbox:android-sync-too-many-open-files into master

We are not unreffing gtask in some code paths. Here, we do it immediately after g_task_run_in_thread (), as the function takes ref to the task and unrefs it when the task is completed.

This was causing the system error "too many open files", as the encoder was not getting unreffed, causing the pipeline not getting unreffed, causing the gstreamer poll loop not getting unreffed, causing the socketpair() used by the poll loop to not close. So, for each track transfer, 2 fds were lost, causing the system error when the open file count per process crossed the user ulimit of 1024 ( which normally happens when transferring more than 350 tracks ).

$ lsof -p $(pgrep -x rhythmbox)  | grep "type=STREAM" | head
rhythmbox 120809 sys    4u     unix 0x00000000fa55a253      0t0  899163 type=STREAM
rhythmbox 120809 sys    5u     unix 0x00000000e3b59872      0t0  899164 type=STREAM
rhythmbox 120809 sys    8u     unix 0x00000000f4b04ace      0t0  898141 type=STREAM
rhythmbox 120809 sys   14u     unix 0x00000000eb423647      0t0  898775 type=STREAM
rhythmbox 120809 sys   16u     unix 0x00000000c906a650      0t0  899480 type=STREAM
rhythmbox 120809 sys   18u     unix 0x00000000cfd51295      0t0  900664 type=STREAM
rhythmbox 120809 sys   19u     unix 0x0000000095dd54ed      0t0  910447 type=STREAM
$ lsof -p $(pgrep -x rhythmbox)  | grep "type=STREAM" | wc -l
900
$ rhythmbox
(rhythmbox:120809): Rhythmbox-WARNING **: 22:44:29.085: got encoding error GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure., but already have one: Could not open resource for reading and writing.
(rhythmbox:120809): Rhythmbox-CRITICAL **: 22:44:29.085: rb_encoder_gst_emit_completed: assertion 'encoder->priv->completion_emitted == FALSE' failed
(rhythmbox:120809): GStreamer-CRITICAL **: 22:44:29.500: gst_poll_get_read_gpollfd: assertion 'set != NULL' failed
(rhythmbox:120809): GStreamer-CRITICAL **: 22:44:29.925: gst_bus_create_watch: assertion 'bus->priv->poll != NULL' failed
(rhythmbox:120809): GStreamer-CRITICAL **: 22:44:29.925: Creating bus watch failed

error1

error2

Edited by crvi

Merge request reports