How to clear "error Previous request not completed" ?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Fri Nov 03, 2017 6:45 pm

Hi all, similar subjects have been discussed on the forum long time ago therefore I decided to post as new.

I'm running LC Indy 8.1.6 and Dropbox API library 2.0 with an iOS App that is constantly (24 x 7) downloading/uploading data from/to Dropbox. From time to time the App hangs. I (guess) I was able to find out that it happens when the connection drops in the middle of a transfer.

I'm able to reproduce the behaviour by running on the simulator and removing my ethernet wire in the middle of a transfer.

I'm getting 3 different errors:

1 - "tsneterr: (6) Couldn't resolve host 'content.dropboxapi.com'
2 - "tsneterr: (7) Failed to connect to content.dropboxapi.com port 443: Operation timed out
3 - error Previous request not completed

It seems errors 1 & 2 go away once the connection is back again.

But the last one "error Previous request..." once received never disappears.

I'd like to try a way to clear this error "manually" and see what happens but I wasn't able to find out how to clear it.

Any ideas how to deal with it? I've tried

Code: Select all

tsNetClose
wait for 5 seconds
tsNetInit
with no success.

I have been dealing with this problem for several months now and am really desperate to find out a solution or work around..

Thanks
Simon
________________________________________
To ";" or not to ";" that is the question

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5562
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to clear "error Previous request not completed" ?

Post by jacque » Sat Nov 04, 2017 8:10 pm

That error was the bane of my existence. It comes from the original libURL, and when TSNet was implemented it kept all the old behavior from libURL but added advanced features as well as speed and enhanced capabilities. One of the enhancements was the ability to do synchronous requests, which the old libURL didn't have. An Indy license does not implement automatic synchronous requests but it does provide the raw handlers that let you write your own script to implement it. I have an example stack if you want to try it, or you can upgrade to the Business edition where it will take care of itself.

Back when libURL was the only library available, Chipp Walters came up with a workaround. It works some of the time, but not all. When you send a request to the server, do it like this:

Code: Select all

      repeat 5 times -- Chipp's method for unreliable connections
        get url tURL
        put the result into tNetworkErr
        put it into tData
        if not needToRetry(tNetworkErr) then exit repeat
        wait 100 milliseconds -- don't use "with messages", let it block to avoid duplicate user requests
      end repeat
And here is the function:

Code: Select all

function needToRetry pError -- Chipp's
  if pError is "timeout" or pError contains "socket timeout" or pError contains "error socket closed" \
        or pError contains "Previous request not completed" then
    return true
  else
    return false
  end if
end needToRetry
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Sun Nov 05, 2017 1:26 pm

Hi Jacque, many thanks for your answer, sorry to say but somehow gives me comfort to learn I'm not the only one suffering from this...

Upgrading to the Business edition is not an option for me as I'm mainly a hobbyist developing no revenue generating Apps and in my view point LC should fix it for the Indy license as well.

As per your suggestion I will go with Chipp Walters workaround and will use "100" in the repeat instead of 5 !!!

I have also noticed that is a good/safe practice to wait more than 1 second in between calls to the Dropbox API

Best!
Simon
________________________________________
To ";" or not to ";" that is the question

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5562
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to clear "error Previous request not completed" ?

Post by jacque » Sun Nov 05, 2017 5:39 pm

Note that sometimes the error never goes away and you'll still have a hung connection. The magic word to clear out everything is "resetAll". It's highly discouraged because it wipes out the entire TSNet connection. You'll need to reinitialize any customization you've done, like custom headers.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 686
Joined: Fri Feb 06, 2015 4:03 pm

Re: How to clear "error Previous request not completed" ?

Post by LiveCode_Panos » Thu Nov 09, 2017 2:27 pm

Hi Simon,

I think the handler Jacque posted as a workaround will work in your case.

BTW you can avoid calling "resetAll" (to clear everything), by just calling "tsNetCloseConn pID", which will remove just the specified connection.

Note that the pID param is the ID of the connection (and *not* the URL as I had mistakenly said in a previous conversation - sorry about that). So in your case you can do something like:

Code: Select all

dropboxUpload pAccessToken, "/largefile.txt", pMode, pAutorename, pMute, tData, myCallback 
..

Code: Select all

on myCallback pRequestID, pHttpResponseCode, pData
   put "response : "&  pHttpResponseCode after fld "response"
   put "data : " & cr &  pData into fld "data"
   
   if pHttpResponseCode is 200 then
      answer "Success"
   else
      tsNetCloseConn pRequestID
      answer "Failure"
   end if
end myCallback
Best,
Panos
--

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Thu Nov 09, 2017 2:35 pm

Thanks Panos, since I'm only using the "plain" DropBox API with no customization at all I doesn't matter to me issuing a resetAll as I'm assuming next time I call the DB API it will handle whatever is necessary to work again. Am I right?
Simon
________________________________________
To ";" or not to ";" that is the question

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 686
Joined: Fri Feb 06, 2015 4:03 pm

Re: How to clear "error Previous request not completed" ?

Post by LiveCode_Panos » Thu Nov 09, 2017 2:42 pm

Yes, in this case I think you should be fine by just calling a "resetAll"

charlesBUSd8qF
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 38
Joined: Wed Apr 11, 2012 10:28 pm

Re: How to clear "error Previous request not completed" ?

Post by charlesBUSd8qF » Mon Nov 13, 2017 3:21 am

Hi Simon,

I recommend adding the following code prior to using the Dropbox API to see if it fixes your issue:

tsNetSetTimeouts 30, , 300000, 60000, 30, 1000

This adjusts the default timeout settings in tsNet so that if a transfer goes idle for 30 seconds, it will close the connection which should prevent “previous request not completed” error you are seeing.

Let me know how it goes, as I might make this the default for tsNet in the future.

Regards,

Charles

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5562
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to clear "error Previous request not completed" ?

Post by jacque » Mon Nov 13, 2017 4:29 am

@Charles, this is very helpful. Is the current timeout still 10 seconds? The problem I see most often is that if there is any delay at all, the user repeats the action over and over again, which triggers more internet requests and the errors pile up. In my app I could use a timeout of 5 seconds or even less. Would there be any problems with that?

Thanks for chiming in here.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

charlesBUSd8qF
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 38
Joined: Wed Apr 11, 2012 10:28 pm

Re: How to clear "error Previous request not completed" ?

Post by charlesBUSd8qF » Mon Nov 13, 2017 8:07 am

Hi Jacque,

The default setting for tsNet is for no timeout during transfer, which is likely why this issue is occurring.

You can reduce this as low as you feel comfortable based on your specific application and how it is used. If the app is expected to be very responsive, then I can’t see any issue with reducing it down to 5 seconds other than that some users might get timeouts if they are on poor Internet connections.

If you set the second last parameter to tsNetSetTimeouts to 5, and the last parameter to 1000, that will tell tsNet to consider a connection as dead if it doesn’t see 1000 bytes of data within 5 seconds during a download transfer.

Best Regards,

Charles

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Mon Nov 13, 2017 12:12 pm

Charles many thanks for your answer/suggestion. I really have high expectations since both previous suggestions (Jacque's and Panos') didn't work.

It seems I'm doing something wrong because my simple test script (attached) hangs when I introduce the line of code you suggested (even with a solid internet connection).

This is my test code

Code: Select all

on mouseUp
   set the text of field "lblStatus" to empty
   -- when the following line is uncommented script hangs
   -- even with good network connection
   -- tsNetSetTimeouts 30, , 300000, 60000, 30, 1000
   dropboxDownLoad pAccessToken, "/command.txt", LoopCallBack
end mouseUp

on LoopCallback pRequestID, pHttpResponseCode, pData     
   -- Response = 200 means OK
   set the text of field "lblStatus" to pHttpResponseCode
   if (pHttpResponseCode is 200)  then
      set the text of field "lblStatus" to "OK"  
   else
      set the text of field "lblStatus" to "Failure"
      resetAll
   end if
   send "mouseUP" to button "Start" in 1 second
end LoopCallback

BTW "command.txt" is a very small file with less than 10 bytes.

Looking forward for your insights.
Attachments
Crash4.livecode.zip
(26.73 KiB) Downloaded 49 times
Simon
________________________________________
To ";" or not to ";" that is the question

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Mon Nov 13, 2017 5:42 pm

I really don't know why but now the test script doesn't hang up anymore. I will put the changes into production and will report back the result as soon as I reach a conclusion.

Many thanks
Simon
________________________________________
To ";" or not to ";" that is the question

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Mon Nov 13, 2017 5:57 pm

Charles, please help me to understand if this is the expected behaviour (I don't think so)

I'm running the stack on the simulator:

1 - Have my Mac connected trough wifi with a good connection
2 - Press start. The OK message is displayed every one second as expect. Sometimes it never shows OK and lblStatus remains "empty"
3 - Drop the wifi connection
4 - I would expect the "Failure" message to appear, but nothing happens, Display remains "empty"
5 - Reconnect the Wifi: I would expect App to start running again but it doesn't.
Simon
________________________________________
To ";" or not to ";" that is the question

charlesBUSd8qF
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 38
Joined: Wed Apr 11, 2012 10:28 pm

Re: How to clear "error Previous request not completed" ?

Post by charlesBUSd8qF » Tue Nov 14, 2017 5:06 am

Hi Simon,

I am not sure the resetAll command will help in that specific piece of code.

When you are testing in the simulator, are you using the tsNetSetTimeouts line of code or is it commented out?

If it is commented out, then the behaviour you are seeing is possible. The dropbox call may be hanging indefinitely (despite reconnecting the wifi) which would mean that the loopback function is never called.

However, if you are seeing this even with the tsNetSetTimeouts command in place, please let me know, as that would indicate there is something else going on.

On a related note, are you still getting the app hanging even with a good Internet connection if you include the tsNetSetTimeouts command?

Regards,

Charles

simon.schvartzman
Posts: 417
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: How to clear "error Previous request not completed" ?

Post by simon.schvartzman » Tue Nov 14, 2017 10:37 am

Hi Charles many thanks for your reply, I really need to fix it and you seem to be my last hope! Answers below
I am not sure the resetAll command will help in that specific piece of code.
If you are not sure what could I say? Any alternatives? Would it harm in someway being there?
When you are testing in the simulator, are you using the tsNetSetTimeouts line of code or is it commented out?
If I use it the stack hangs completely in spite of having a good internet connection.
If it is commented out, then the behaviour you are seeing is possible. The dropbox call may be hanging indefinitely (despite reconnecting the wifi) which would mean that the loopback function is never called.
This is precisely the problem I'm trying to solve!
However, if you are seeing this even with the tsNetSetTimeouts command in place, please let me know, as that would indicate there is something else going on.
As said above yes I'm experienced the hang out even with the Timeouts set as per your suggestion. I guess I found something. As can be seen on the screen below, when I try to run the stack on the IDE an error is generated at execution time:

"button "Start": execution error at line n/a (External handler execution error: parameter 'pRequestTimeout' is not a number) near "parameter 'pRequestTim"
screen.jpeg
On a related note, are you still getting the app hanging even with a good Internet connection if you include the tsNetSetTimeouts command?
Yes, same as above.

Charles I'd really appreciate a quick turn around as this is going on for months and I'm desperate to get the App running without interruptions. Many thanks in advance
Simon
________________________________________
To ";" or not to ";" that is the question

Post Reply

Return to “Talking LiveCode”