Talk:Server.pl

From Organic Design wiki
Revision as of 05:10, 9 May 2006 by Nad (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  1. Bugs & Notes
    1. HTTP Authentication

Currently HTTP authentication is just base64 encoded username:password which is basically just plain text, so the password can easily be discovered.

    1. Port-binding bug

Socket can't bind to port for a minute or so after peer stops. Shutting it officially, blocking, autoflush don't work.

Found the problem when doing some other socket research! see Unix Socket FAQ, which talks about this exact issue :-) --Nad 23:14, 30 Mar 2006 (NZST)
This may be due to going directly into init.d rather than inetd --Nad 09:34, 28 Mar 2006 (NZST)
Problem solved, use ReuseAddr => 1 in IO::Socket->new --Nad 17:06, 9 May 2006 (NZST)

netstat -tupl and lsof -i 1729 shows that the port is freed immediately, but it still won't bind until after the delay.

    1. HTTP-Response issue

For some reason certain clients cannot receive a the content from the peer. The headers are received, but then the client times-out waiting for the content. This is odd because the code sends the entire header and message in one go...?!?! The main problem is that one of the clients that fails is the one used by the fopen-wrappers in PHP!

  • Using PHP's fsockopen() I've made a workaround for now, by making a request, but not doing a corresponding fgets() which is the one that won't return (see notify-peer.php). --Nad 09:34, 28 Mar 2006 (NZST)
  • It seems to be an HTTP/1.0 problem (both wget and PHP's fopen-wrappers use HTTP/1.0)
  • Actually, it turns out it does return, but only after a long timeout (another clue!)

Here's what happens when we request from the peer using wget which is also one of the failing clients:

closet:/home/nad# wget http://localhost:1729
--13:50:01--  http://localhost:1729/
           => `index.html'
Resolving localhost... 127.0.0.1
Connecting to localhost[127.0.0.1]:1729... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3,744 [text/html]

 0% [                                 ] 0   --.--K/s

As you can see it must have retreived the headers to know the Content-Type and Content-Length, and is now waiting for the content, not more headers - but why is it waiting when the peer code sends the whole headers+message in one go?

It works fine for curl, and Rob used:

curl -vi http://organicdesign.co.nz:1729 --trace-ascii /dev/tty

to obtain the results listed below (the data has been omitted for brevity). I've commented some different lines to show that those differences have been tested and are not the issue...

== Info: About to connect() to organicdesign.co.nz port 1729
== Info:   Trying 58.28.135.7... == Info: connected
== Info: Connected to organicdesign.co.nz (58.28.135.7) port 1729
=> Send header, 181 bytes (0xb5)
0000: GET / HTTP/1.1
0010: User-Agent: curl/7.13.2 (i386-pc-linux-gnu) libcurl/7.13.2 OpenS
0050: SL/0.9.7e zlib/1.2.2 libidn/0.5.13
0074: Host: organicdesign.co.nz:1729
0094: Pragma: no-cache
00a6: Accept: */*
00b3: 
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 38 bytes (0x26)
0000: Date: Mon, 27 Mar 2006 11:57:45 NZST           // HTTP1.1 insists on GMT, but that didn't fix it
<= Recv header, 15 bytes (0xf)
0000: Server: wikid
<= Recv header, 22 bytes (0x16)
0000: Content-Length: 3744
<= Recv header, 46 bytes (0x2e)
0000: Content-Disposition: inline;filename=Gir.swf   // removing this header didn't fix it
<= Recv header, 19 bytes (0x13)
0000: Connection: close                              // this has been removed now giving "left intact"
<= Recv header, 25 bytes (0x19)
0000: Content-Type: text/html
<= Recv data, 1264 bytes (0x4f0)
============================ DATA ============================
== Info: Connection #0 to host organicdesign.co.nz left intact    // added manually since it gives this now
== Info: Closing connection #0

An here are the headers returned from another site which works fine from wget:

== Info: About to connect() to www.cs.auckland.ac.nz port 80
== Info:   Trying 130.216.33.106... == Info: connected
== Info: Connected to www.cs.auckland.ac.nz (130.216.33.106) port 80
=> Send header, 178 bytes (0xb2)
0000: GET / HTTP/1.1
0010: User-Agent: curl/7.13.2 (i386-pc-linux-gnu) libcurl/7.13.2 OpenS
0050: SL/0.9.7e zlib/1.2.2 libidn/0.5.13
0074: Host: www.cs.auckland.ac.nz
0091: Pragma: no-cache
00a3: Accept: */*
00b0: 
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 37 bytes (0x25)
0000: Date: Sun, 26 Mar 2006 23:58:03 GMT
<= Recv header, 30 bytes (0x1e)
0000: Server: Apache/1.3.33 (Unix)
<= Recv header, 30 bytes (0x1e)
0000: Cache-Control: max-age=18000
<= Recv header, 40 bytes (0x28)
0000: Expires: Mon, 27 Mar 2006 04:58:03 GMT
<= Recv header, 28 bytes (0x1c)
0000: Transfer-Encoding: chunked
<= Recv header, 25 bytes (0x19)
0000: Content-Type: text/html
<= Recv data, 2687 bytes (0xa7f)
============================ DATA ============================
== Info: Connection #0 to host www.cs.auckland.ac.nz left intact
== Info: Closing connection #0

I made server.pl dump all input to the log before splitting into message etc, here's what curl gives:

Mon Mar 27 16:04:31 2006 : [serverStart]	== DATA STARTS ==
Mon Mar 27 16:04:31 2006 : [serverStart]	GET / HTTP/1.1
User-Agent: curl/7.13.2 (i386-pc-linux-gnu) libcurl/7.13.2 OpenSSL/0.9.7e zlib/1.2.2 libidn/0.5.13
Host: organicdesign.co.nz:1729
Pragma: no-cache
Accept: */*


Mon Mar 27 16:04:31 2006 : [serverStart]	== DATA ENDS ==
Mon Mar 27 16:04:31 2006 : [serverStart]	Gir() requested
Mon Mar 27 16:04:31 2006 : [serverStart]	Stream5 disconnected.

...and here's what wget gives:

Mon Mar 27 16:08:12 2006 : [serverStart]	== DATA STARTS ==
Mon Mar 27 16:08:12 2006 : [serverStart]	GET / HTTP/1.0
User-Agent: Wget/1.9.1
Host: localhost:1729
Accept: */*
Connection: Keep-Alive


Mon Mar 27 16:08:12 2006 : [serverStart]	== DATA ENDS ==
Mon Mar 27 16:08:12 2006 : [serverStart]	Gir() requested