Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

embedded library seems to run infinite loop inside parseProcessNextPushNotification function. #61

Open
dfszb opened this issue Jan 21, 2016 · 2 comments

Comments

@dfszb
Copy link

dfszb commented Jan 21, 2016

Testing / evaluating parse using an Ubuntu Linux computer.
Parse UNIX library seems to be in a continuous loop eating 100% of CPU.
The problematic code seems to be in parse.c, function: int parseProcessNextPushNotification(ParseClient client), the following lines:

        while (length == -1 && parse_push_message_size < sizeof(parse_push_message_buffer)) {
            CURLcode result = curl_easy_recv(clientInternal->pushCurlHandle,
                                             parse_push_message_buffer + parse_push_message_size,
                                             sizeof(parse_push_message_buffer) - parse_push_message_size,
                                             &read);
            if (result == CURLE_OK) {
                parseLog(PARSE_LOG_INFO, "got ok!\n");
                parse_push_message_size += read;
                message = (char *)getPushJson(parse_push_message_buffer,
                                              parse_push_message_size,
                                              &start,
                                              &length);
            } else if (result == CURLE_AGAIN) {
                break;
            } else {
                parseLog(PARSE_LOG_ERROR, "curl_easy_recv read %i an error %s\n", length, curl_easy_strerror(result));
                if (clientInternal->pushCallback != NULL) {
                    clientInternal->pushCallback(client, ECONNRESET, NULL);
                }
                return 0;
            }
        }

The while loop continues to run as the CURLcode result = curl_easy_recv returns CURLE_OK.
However the 'read' parameter passed to curl_easy_recv has a value of 0 after call that indicates a closed connection according to http://curl.haxx.se/libcurl/c/curl_easy_recv.html.
The result is 100% cpu utilization and inability to process subsequent push messages.
I think the correct form would be to use if ((result == CURLE_OK) && (read > 0))

@dfszb dfszb changed the title embedded library runs in a loop inside int parseProcessNextPushNotification(ParseClient client) embedded library seems to have infinite loop inside parseProcessNextPushNotification function. Jan 21, 2016
@dfszb dfszb changed the title embedded library seems to have infinite loop inside parseProcessNextPushNotification function. embedded library seems to run infinite loop inside parseProcessNextPushNotification function. Jan 21, 2016
@mtl2034
Copy link
Contributor

mtl2034 commented Jan 25, 2016

Hi @dfszb, let me look at and fix it. Do you have an easy way to reproduce this problem?

@dfszb
Copy link
Author

dfszb commented Jan 26, 2016

It happened randomly. Sometimes just waiting, other times when wifi lost connection.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants