Potential socket issue in LC 7.0.6
Moderator: Klaus
Potential socket issue in LC 7.0.6
So I've created a server that talks to a bunch of client processes using sockets. Problem is, it seems some of the sockets are reused before they are closed. Is this expected? I've attached a screenshot of the command window after running the openSockets command on my server. You can see the duplicate entries for '127.0.0.1:1404'. Should this occur? If not, I will attempt to ween down my code to something that can be added to a bug description. Thanks!
Edit: This is on Windows 7
Edit: This is on Windows 7
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Potential socket issue in LC 7.0.6
Could it be that's a client with two transactions? Without seeing the code of won't be possible to determine what's going on.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Potential socket issue in LC 7.0.6
That's the server side. These are all open sockets created from the accept connections command, in this case:
accept connections on port 61746 with message XXX
The server does not open any sockets any other way. In this particular instance there's no clear way to specify a client in the read to/write from socket commands since both clients connect to the same socket. If you believe this shouldn't occur then I can try to create a smaller test case outside this code to recreate, but it would take some time and I didn't want to do that if I'm thinking of it all incorrectly. Here's the overview of what I am doing within a larger project:
1. Create a server using accept connection on port X.
2. Spawn 20 client processes that connect to the server and receive a task to perform.
3. Task clients disconnect when complete.
The command in the screenshot should illustrate the problem I'm seeing, since even if there were other connections to the same socket wouldn't they have the "|Connection ID" associated with them? Either way I'm sure the server only accepts connections. Thanks for the quick feedback!
accept connections on port 61746 with message XXX
The server does not open any sockets any other way. In this particular instance there's no clear way to specify a client in the read to/write from socket commands since both clients connect to the same socket. If you believe this shouldn't occur then I can try to create a smaller test case outside this code to recreate, but it would take some time and I didn't want to do that if I'm thinking of it all incorrectly. Here's the overview of what I am doing within a larger project:
1. Create a server using accept connection on port X.
2. Spawn 20 client processes that connect to the server and receive a task to perform.
3. Task clients disconnect when complete.
The command in the screenshot should illustrate the problem I'm seeing, since even if there were other connections to the same socket wouldn't they have the "|Connection ID" associated with them? Either way I'm sure the server only accepts connections. Thanks for the quick feedback!
Re: Potential socket issue in LC 7.0.6
No updates? Perhaps someone could answer this question:
Should livecode ever have duplicate entries in the openSockets list?
I would think not, since these describe the peer connections, which should always be unique. Otherwise, how could you know who you were communicating with using read from/write to socket?
Should livecode ever have duplicate entries in the openSockets list?
I would think not, since these describe the peer connections, which should always be unique. Otherwise, how could you know who you were communicating with using read from/write to socket?
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Potential socket issue in LC 7.0.6
Many things are possible, depending on what the code is doing. Without seeing both the client and server code, we may not be able to guess how that seemingly-duplicate entry occurred.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Potential socket issue in LC 7.0.6
It seems rather odd that there is no definitive answer on whether the livecode function openSockets should have duplicates or not. I will gladly pare down my code to something I can post to the forums in the meantime, but it would be nice to know if this should even occur. I asure you nothing nefarious is going on, as in I'm not altering the output of this function in any way, shape, or form.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Potential socket issue in LC 7.0.6
Computers are generally deterministic systems; given the same inputs in the same order will yield the same result. Sometimes sockets are closed after a single use, sometimes used more than once. How they're used in the code in question can only be determined by the code. So whether this should happen or not can't be known right now, but once we see the code for a repeatable example we'll be able to pin down what's going on.russellf wrote:...it would be nice to know if this should even occur.
One side note occurs to me as I read the thread title - are you still testing on v7.0.6 or have you tried a more recent version? The most recent Stable build in the 7.x series is 7.1.1, but for this sort of testing I'd suggest the latest Release Candidate for 7.1.2:
http://downloads.livecode.com/livecode/
I believe some work has been done in areas that may affect sockets, so while (if memory serves) that work was focused on the Server edition it may affect other platforms as well. Maybe it was a bug that was fixed? Maybe it's fine and doing exactly what it should? We'll find out with a little more testing and perhaps some code review.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Potential socket issue in LC 7.0.6
Yes, computers are deterministic, therefore the livecode openSockets function was designed with an intent. Was the intent to allow duplicate entries? Anyway, I'll get some code to review, but it will be a couple of weeks. I've worked around the issue by using another list to track the sockets in use.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Potential socket issue in LC 7.0.6
The sockets IDs come from the OS, and if I read your last post right it seems the fix was in changing the method by which they're listed. Doesn't sound like anything LC is doing at all, but to answer your question "Was the intent to allow duplicate entries?", the answer would be "Depends on what the code is asking it to do."
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Potential socket issue in LC 7.0.6
Looking through the livecode open source project some, the openSockets function is a representation of MCsockets. To read/write a socket, the code looks up the connection id given by a user in MCsockets, say "127.0.0.1:4400" and finds the first entry in the list that matches it. It uses this descriptor to talk to the socket. So it looks to me like the name field in this list should be unique, otherwise which socket would you be talking to?
Re: Potential socket issue in LC 7.0.6
@russellf: You are correct - the openSockets command *should not* produce a list containing duplicate names as those names are used to *uniquely* identify a socket. It does sound like the OS is closing a socket, but LiveCode is not updating its list so that when that socket's port is reused in a subsequent connection you end up with two sockets with the same name. I'm honestly not sure why this is occurring - it is quite possibly a bug caused by a specific sequence of actions your application is taking. If you could file a bug report at http://quality.livecode.com with as much information as possible and ideally a stack reproducing the problem that would be great (if you aren't able to produce a cut down example stack, you can send your actual stack which demonstrates the problem to panos.merakos@livecode.com - just put a note to that effect in the bug report).
Re: Potential socket issue in LC 7.0.6
@LCMark: Thanks for the reply! Good to know I'm not crazy
I will do as you say but it may be some time before I can get this together. Need to get my project released in the next week or two. Thanks again!
