URLConnection multiple request behavior


I have a strange issue that I don’t know how to solve with URLConnection responses.

We are developing a desktop app that use an in-house API written in Python to retrieve data. I call the API using the URLConnection class.

We have a method that set the token to expired after X hours (after the login) on the API side. When I open a window, sometimes there are many requests sent to the back-end simultaneously and it’s when the strange behavior happens.

For example, if I send 3 requests (asynchronous) at the same time. In the ContentReceived Event of URLConnection, I check a custom code that says the token is expired and I set a property (global for the moment for the tests) that say a request arrived with the token expired and all next requests that arrives with the same result are added in an array stored globally.

Next I show a window login to refresh the token and resend all pending requests using the same headers/body and send them again using the new token.

The issue is (sometimes) when I set the boolean that say the token is expired as true, the next requests are seeing the boolean as false (initial value) also whereas I set it to true with the first request.

When I set breakpoints, I see that the first request set it to true and when I look at it on the second request, sometimes it’s still on false.

I don’t know if I miss something or if sometimes the requests responses arrives at the same time, but I think it’s most likely an error in my code.

Thank you,

Xojo version: 2020r1.1
MacOS Mojave 64 bits
(The issue also occurs when I build for Windows 10 64 bits)

The sockets are platform specific. If you get the problems on both macOS and Windows a problem in your code is likely. However, I tried multiple downloads a couple of years ago. After spending a day to make everything behave nicely I ended up with non-reproducible crashes. Curl (CURLSMultiMBS) took about an hour to implement and test and the crashes were gone.

Make an example for testing.


I did an example project but and I think I got the issue but don’t know how to solve it.

Dropbox link

When I click start, it executes all the requests and sometimes when the dialog window appears, I only get 3 responses and the last response come after the close of the dialog.

So I think the issue is that when I show the modal, all non received response are no longer processed while the modal is opened. I thought that the responses of the asynchronous calls were managed in separate thread and that one response did not block an other response. Well I need to figure out something to fix that.

Edit: Had to try like 10-30 times sometimes for the issue to occurs but just pressing enter again and again should do the trick

The problem you are having is likely related to the fact that socket events always fire on the main thread… the thread that is blocked when you call ShowModal.

Thank you, it must be that do you have any hint on how to find a solution for that? Create a thread and call the showmodal from the thread?

For what do you need the showmodal? I’d recommend a refactor without the showmodal.

The modal is used as a login form for the user to login and generate a new token, then I use the new token to send the pending requests.

You don’t need to use ShowModal though. Just set the Window type to modal and then just use Show.

Yes you are right, but I will need to perform some changes in my code as my code was performed right after the showModal line (in the same method)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.