Skip to content
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

Directory polling does not clean up open directory file descriptors #321

Open
2 tasks done
dennisafa opened this issue Aug 24, 2022 · 2 comments
Open
2 tasks done
Labels

Comments

@dennisafa
Copy link

dennisafa commented Aug 24, 2022

Checklist (Please check before submitting)

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
CF_CFDP_PlaybackDir is called by CF_CFDP_ProcessingPollingDirectories when the interval for the CF_Poll_t structure has expired. This function will attempt to reopen the directory. If the polling directory does not continuously receive new files to process, then the OS_DirectoryOpen call happens without a corresponding OS_DirectoryClose call, exhausting the amount of available file descriptors and causing this error.
CF: failed to open playback directory /cf/dl , error=-14

To Reproduce
Steps to reproduce the behavior:

  1. Launch CF with a configured polling directory
  2. Let ticker expire and attempt to reopen directory
  3. Wait until FDs are exhausted and error appears

Expected behavior
I expect the directory file descriptor to be cleaned up before each OS_DirectoryOpen call.

Code snips
Configuration table used:

CF_ConfigTable_t CF_config_table = {
    10,       /* ticks_per_second */
    33554432, /* max number of bytes per wakeup to calculate r2 recv file crc */
    24,       /* temp local id */
    {{
         32,   /* max number of outgoing messages per wakeup */
         512, /* max number of rx messages per wakeup */
         5,   /* ack timer */
         5,   /* nak timer */
         30,  /* inactivity timer */
         8,   /* ack limit */
         8,   /* nak limit */
         CF_PDU_CMD_MID,
         CF_PDU_TLM_MID,
         512,
         {{1, 0, CF_CFDP_CLASS_1, 21, "/cf/dl", ".", 1}, {0}, {0}, {0}, {0}},
         "", /* throttle sem for channel 1, empty string means no throttle */
         1,
     }},
    1253, /* outgoing_file_chunk_size */
    "/ram",
};

System observed on:

  • SC3M, Microblaze
  • OS: Linux 5.4
  • cFS 7.0, CF commit bff67f8

Additional context
I added a check in CF_CFDP_PlaybackDir that looks to see if the FD is 0. If it isn't, I close the directory and reopen it. This gets rid of the problem.

Reporter Info
Dennis Afanasev, NASA Goddard Code 587

@skliper
Copy link
Contributor

skliper commented Aug 24, 2022

I'm not quite following. The initiate should only happen if the polling directory isn't busy:

CF/fsw/src/cf_cfdp.c

Lines 1584 to 1596 in 8053882

if (!p->pb.busy && !p->pb.num_ts)
{
if (!p->timer_set)
{
/* timer was not set, so set it now */
CF_Timer_InitRelSec(&p->interval_timer, pd->interval_sec);
p->timer_set = 1;
}
else if (CF_Timer_Expired(&p->interval_timer))
{
/* the timer has expired */
int ret = CF_CFDP_PlaybackDir_Initiate(&p->pb, pd->src_dir, pd->dst_dir, pd->cfdp_class, 0,
chan_index, pd->priority, pd->dest_eid);

And busy is only set to zero when the directory has been closed and there's no remaining transactions:

CF/fsw/src/cf_cfdp.c

Lines 1499 to 1511 in 8053882

else
{
/* PFTO: can we figure out the difference between "end of dir" and an error? */
OS_DirectoryClose(p->dir_id);
p->diropen = 0;
}
}
if (!p->diropen && !p->num_ts)
{
/* the directory has been exhausted, and there are no more active transactions
* for this playback -- so mark it as not busy */
p->busy = 0;

Can you elaborate on the flow that causes multiple directory opens without a close?

@skliper
Copy link
Contributor

skliper commented Aug 24, 2022

Tried to recreate using the main branch and I see a successful close for every open. Any chance there's something else using up the FDs?

@dzbaker dzbaker added the bug label Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants