[GOODIE] [CRASH] [UNIX] Multiuser chat server.

Scott A Crosby crosby at qwes.math.cmu.edu
Fri Sep 21 02:14:10 UTC 2001


All of this is done on  3.1alpha (change set 4164-4332) under x86 linux.

I've been working on parts of my (hopefully) eventual multiuser chat
server. Here's what I've done so far; it shows a wide variety of bugs
under this version of squeak.



First, a simple bug to warm everyone up.
  Invoke squeak with  'squeak -memory'
*segfault*




-- How to use:
 Install the changeset.
 Load the workspace and cut&paste the initialization lines, then cut&paste
a socket-listener line.

 Then use a telnet or other MUCK client and connect to the port.

There are currently 2 servers built into it, an 'echo server' which just
echo's each line you type, and a 'simplechat' which allows simple
chatting.

To log into the simplechat server just do:
  'simplechat Foo'
And type away.

You can also log into it multiple time. (In fact I suggest it.)

Note that there may be 10 second pauses (explained below) so be patient.

Thats it. Codewise, its fully functional, in that all the code thats
written works. In practice, due to the listed bugs below, it is not really
usable. It was a test so I could see how well squeak would work to
implement one. I'm working on a much more realistic replacement.


Note!!!!! -- Do not do this in an image you care about.

I repeat ** DO NOT DO THIS IN AN IMAGE YOU CARE ABOUT **

--

Design. I use multitasking. I spawn one thread to run the main loop. I
spawn one thread for each socket it listens on. When a new connection
happens, it spawns two threads for that connection, one to handle input,
one to handle output.

Concurrency is hard, so I get rid of it as soon as possible; All the
reader threads put a handler object onto a shared queue, which the main
thread pops objects off and invokes. This means that all the code in the
main thread does not have to worry about concurrency. It also means that
no such handler may pause for too long.

My chat program was primarly to test out this code; get an idea how fast
it went, or how squeak would behave... It behaves fast enough (it'll
handle 300 lines/sec in and write 300 lines/sec to each of 9 output
windows.). But the behaivor, given the below bugs, is blah...

--

Bugs:

#1 [crash]:  Try to connect to the server about 10-20 times, don't type in
anything. It freezes,

When doing this, I've seen squeak replace transcript windows with big red
squares (with a yellow cross through the middle of them. Though it brings
up a debugger before completely drawing it.  At that point, squeak seems
to no longer see the mouse or keyboard. Though it will refresh the screen.
Not even emergency-escape works.

#2 [crash]: Connect to the server with one or more times. Paste a lotta
text into the windows... hundreds of kilobytes. Try more windows and more
concurrent connections.. I've seen walkbacks, strange crashes, and
complete.

#3 [crash]: There was a diff patch a few weeks ago that fixes this, but
the socket finalization C code is in error, and may crash, both when
saving an image with open sockets, or when loading an image that had open
sockets on it when it was saved. I've not checked for a more recent unix
sourcetree to confirm this. It may help to reduce the deadlineSecs:
MuckSocket>>waitForData to one second. (See #5 for more on this)

#5 [annoyance]: The sockets code appears to be somewhat flawed when
waiting for data. Connect to the echo server, and wait 20 seconds and type
a line. It comes out immediately. Type another line a second later, and
squeak waits about 10 seconds. Its like after a successful read, it will
not do another read on the socket for deadlineSecs
(MuckSocket>>waitForData) But, if its been more than 10 seconds since a
read, it will notice the new data immediately.

Note that it may read multiple lines of input in one read, so if you type
in:
  'foo' (wait one sec)
  'bar' (then immediately)
  'baz'

The bar&baz will come out all at once, approximately 10 seconds after
'foo' comes out.

This is the source of some of the strangish delays in the login program
and stuff.


#6 [flaw] There appear to be several busywaits in squeak. Try
connecting to the server, but doing nothing. You may find squeak consuming
all CPU. My code responsible for network reading is::

   MuckPlayerConnection>>networkReaderLoop,
   MuckSocket>>networkGetSingleLine
   MuckSocket>>waitForData

Where the first funciton is the main reader loop, and the last one is
where I invoke the socket primitives.  According to profile, that loop is
busywaiting.

I have a 10 second timeout, but I believe the underlying C code is
not waiting even despite this.
--

Anyways, grab, run, enjoy, beat the code up and see how squeak breaks.

For example, try running this code through Jitter, or while profiling
messages.

Finally, there are a few indications that some of these problems may be
low-memory issues, though I have 5mb free.

Enjoy!

--
Its been interesting to find what I've found in squeak..

I've heard that the flow framework (http://netjam.org/flow/) is supposed
to be sockets done right.. True? If so, when will it be integrated into
the main squeak distribution? Will it?

As far as other integration goes, any timeline when Stephen Pair's
delegation will be coming into the main image?


I ask when it'll be integrated, because I suspect that code thats
integrated into the distribution is much less likely to suffer from
bitrot... Which is why I'm waiting for them to be included.


Scott


--
No DVD movie will ever enter the public domain, nor will any CD. The last CD
and the last DVD will have moldered away decades before they leave copyright.
This is not encouraging the creation of knowledge in the public domain.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MuckClassesWorkspace.text.gz
Type: application/x-gzip
Size: 781 bytes
Desc: The howto
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010920/09ef21ee/MuckClassesWorkspace.text.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MuckClasses.1.cs.gz
Type: application/x-gzip
Size: 9974 bytes
Desc: The code
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010920/09ef21ee/MuckClasses.1.cs.bin


More information about the Squeak-dev mailing list