Socket Problems

Andreas Raab andreas.raab at gmx.de
Fri Sep 12 19:30:32 UTC 2003


> The result of the posted code on the production server (Debian Linux, 
> Squeak Unix VM 3.6-beta6) is the following (with -notimer 
> already turned on):
> 
> 	a) client statusString.    --> 'connected'
> 	b) client getData.         --> 'Response'
> 	c) client statusString.    --> 'connected'
> 	d) client getData.         --> 'getData timeout' 
> exception is raised
> 	e) client statusString.    --> 'otherEndClosedButNotThisEnd'
> 
> Is this ok?

This looks very reasonable to me. The situation I was thinking about was
that a) would report immediately "otherEndClosedButNotThisEnd" (which is
depending on the implementation quite possible - I had this on Windows some
point in the past). So this doesn't seem to be the problem I was thinking
about.

> I've tried to run in several times, but it looks all the 
> time the same. Should we try it in a loop? Should we write a 
> test that runs it in parallel with different sockets?

No, I don't think so. The above test tells us that the VM responds "as if"
you were calling recv() directly on the socket which is the correct
behavior.

> > Yes they are. Unless you attempt to use the same socket 
> > simultanously from different threads there is no problem. 
> > If you do the latter then you have the "common" issues of
> > synchronizing access to a shared resource from different 
> > threads.
> 
> Ok, lets check that on the production machine: 
> 
> 	PGConnection allInstances collect: [ :each | each instVarAt: 4 ]
> 	--> #(a Socket[connected] a Socket[connected] a 
> Socket[connected] ...
> 
> 	PGConnection allInstances collect: [ :each | (each 
> instVarAt: 4) 
> oopString ]
> 	--> #('1810' '2601' '1928' '1596' '2804' '2495' '3428' 
> '194' '3276' ...
> 
> All sockets used by the PGConnection instances seem to be different, 
> right? So this should be not the problem.

Perhaps better:
	| usedSet |
	usedSet := IdentitySet new.
	PGConnection allInstancesDo:[:each|
		| socket |
		socket := each instVarAt: 4.
		(usedSet includes: socket)
			ifTrue:[self error: 'Socket shared by multiple
connections].
		usedSet add: socket.
	].

> 
> > First of all, run the above example and see what this gets
> > you. It may be that the VM is merely reporting that the 
> > "otherEndClosedButNotThisEnd" and that your code deduces from
> > this that there is no readable data on the socket (e.g., 
> > #isConnected will return false which in turn may screw 
> > #getData and friends). In this situation you may still be able
> > to read data from the socket (can't say without having tried
> > it; but see what #primSocket:receiveDataInto:startingAt:count:
> > reports) and simply work around this problem.

[snip]

> I do not understand what you actually suggest to change.

Nevermind. This was under the assumption that a) reports
otherEndClosedButNotThisEnd. It is of no importance any longer.

That said, it would be interesting to find out where your code actually
fails - from the above you can see that if the server closes the connection
rapidly, you can have time outs very soon (for example in a loop) and maybe
that's your problem. It would be helpful if you could investigate some of
the cases where you get the error and report the expected and actual state
back.

Cheers,
  - Andreas




More information about the Squeak-dev mailing list