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

Bug in WiFiSocket.cpp causing infinite loop #278

Open
S2Doc opened this issue Sep 3, 2019 · 3 comments
Open

Bug in WiFiSocket.cpp causing infinite loop #278

S2Doc opened this issue Sep 3, 2019 · 3 comments
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project

Comments

@S2Doc
Copy link

S2Doc commented Sep 3, 2019

WiFiSocket::write() contains the following loop:

while ((err = send(sock, (void *)buf, size, 0)) < 0) {
  // Exit on fatal error, retry if buffer not ready.
  if (err != SOCK_ERR_BUFFER_FULL)  {
    size = 0;
    break;
  } else if (hif_receive_blocked) {
    size = 0;
    break;
  }
  m2m_wifi_handle_events(NULL);
}

Note that if the call to send() returns with err = SOCK_ERR_BUFFER_FULL, the while loop never exits unless hif_receive_blocked becomes true. I frequently (several times per day) experience this situation. There is no way to exit this loop other than by watchdog timer forcing a reset.

As a possibly relevant side-note, the call to send() (in socket.c) can return only the SOCK_ERR_BUFFER_FULL error. No matter what error actually occurred, send() will always misleadingly return the same error.

@S2Doc S2Doc changed the title Bug in WiFiCocket.cpp causing infinite loop Bug in WiFiSocket.cpp causing infinite loop Sep 3, 2019
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Sep 6, 2019
@sandeepmistry
Copy link
Contributor

Hi @S2Doc,

Do you have steps to reproduce this condition? What f/w is your WINC1500 running?

Another option to your proposal would be to have a retry timeout.

@sandeepmistry sandeepmistry added the status: waiting for information More information must be provided before work can proceed label Sep 18, 2019
@S2Doc
Copy link
Author

S2Doc commented Sep 18, 2019

I have experienced this problem when sending MQTT packets at 3-5 second intervals. It occurs after as few as 2 packets have been sent or only after tens of thousands. It does not seem to correlate with losing the MQTT connection, although it is impossible to be totally certain of this.

The problem occurs with WINC1500 firmware v19.4.4 and v19.5.4. I have not tested with other versions.

I have had good results by counting the number of times through the while loop and exiting after the 10th try. Using a timeout to exit the loop would be a good alternative as long as the length of the timeout was adjustable, perhaps through a #define, so that any watchdog timer set by the user will not cause a reset before the timeout is reached.

@S2Doc
Copy link
Author

S2Doc commented Sep 18, 2019

Note that there are other places in WiFiSocket.cpp with loops that may never exit. Another is in WiFiSocket::Connect(), see #279.

WiFiSocketClass::bind and WiFiSocketClass::listen also have hard-coded timeouts which may cause problems if the user sets a watchdog timer to reset before the timeout has occurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants