CESNET / libnetconf

C NETCONF library
Other
113 stars 83 forks source link

netopeer-agent 100% CPU usage after "edit-config: Unknown error occurred." #244

Open SeanCondon opened 7 years ago

SeanCondon commented 7 years ago

Hi - just FYI

I had a problem with calling edit-config from netopeer-cli when passing a large config (76k) through dropbear.

Dropbear has a default chunk size of 24kB and so the message was getting split up. Somehow this causes an error in a file descriptor I think between dropbear and the netopeer-agent. When I close the client the CPU usage of netopeer-agent goes to 100%.

I don't know what causes the first problem, but the 100% problem is cause in the file libnetconf/src/session.c int nc_session_read_len(..)

Starting on line 1644 (with libnetconf 0.9.1, line 1658 with libnetconf 0.10.0), I added in the condition } else if (c == 0) { and it stops the process going to 100% and now it exits the client cleanly:

    if (session->fd_input != -1) {
            /* read via file descriptor */
            c = read (session->fd_input, &(buf[rd]), chunk_length - rd);
            if (c == -1) {
                if (errno == EAGAIN) {
                    usleep (NC_READ_SLEEP);
                    continue;
                } else {
                    ERROR("Reading from an input file descriptor failed (%s)", strerror(errno));
                    free (buf);
                    *len = 0;
                    *text = NULL;
                    return (EXIT_FAILURE);
                }
            } else if (c == 0) {
                ERROR("Reading from an input file descriptor failed (%s) c=0, fd closed unexpectedly.", strerror(errno));
                free (buf);
                *len = 0;
                *text = NULL;
                return (EXIT_FAILURE);
            }
        } ....

To solve the other problem, I increased the dropbear window size to 512kB, with the -W option