TCP Server Socket issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

TCP Server Socket issue

Holger Freyther
Hi,

I am in a train and hope you excuse my laziness. I have selector like this

listen [
       | con |
        socket := Sockets.ServerSocket
                    port: port
                    bindTo: (Sockets.SocketAddress byName: addr).

        [true] whileTrue: [
            socket waitForConnection.
            con := socket accept.
            con close.
        ]
]

and this is silently on the GST shell when I CTRL+C and listen again. So the
old ServerSocket is still around when I create the new one. I would like to
either have an exception (e.g. when the bind(2) is failing) or it to magically
work (how would it)?

Is it worth to look into the underlying issue?

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: TCP Server Socket issue

Paolo Bonzini-2
On 11/07/2010 09:55 PM, Holger Hans Peter Freyther wrote:

> Hi,
>
> I am in a train and hope you excuse my laziness. I have selector like this
>
> listen [
>         | con |
>          socket := Sockets.ServerSocket
>                      port: port
>                      bindTo: (Sockets.SocketAddress byName: addr).
>
>          [true] whileTrue: [
>              socket waitForConnection.
>              con := socket accept.
>              con close.
> ]
> ]
>
> and this is silently on the GST shell when I CTRL+C and listen again. So the
> old ServerSocket is still around when I create the new one.

Do you have a strace?  It should raise an exception:

     [(self
         bind: fd
         to: addr
         addrLen: addr size) < 0 ifTrue: [File checkError: self soError]
             ifCurtailed: [self close].

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: TCP Server Socket issue

Holger Freyther
On 11/11/2010 03:32 PM, Paolo Bonzini wrote:
> On 11/07/2010 09:55 PM, Holger Hans Peter Freyther wrote:

>>
>> and this is silently on the GST shell when I CTRL+C and listen again. So the
>> old ServerSocket is still around when I create the new one.
>
> Do you have a strace?  It should raise an exception:
>
>     [(self
>         bind: fd
>         to: addr
>         addrLen: addr size) < 0 ifTrue: [File checkError: self soError]
>             ifCurtailed: [self close].

Hi,

it took me a bit. So below is the test case, the result in terms of netstat,
the output of strace. So the bind is failing but the socket has no SOL_ERROR
at all... instead we end up listening (didn't see that) on a socket that is
not properly configured.

From a quick look at the socket/ipv4/ipv6 impl I don't see anyone assigning
sk_err to anything in case of a failed bind, so I am not sure where the
SO_ERROR != 0 on failed bind is coming from.



st> server1 := Sockets.ServerSocket port: 8080 bindTo: addr.
Sockets.ServerSocket[127.0.0.1:8080]
st> server2 := Sockets.ServerSocket port: 8080 bindTo: addr.
Sockets.ServerSocket[0.0.0.0:0]

on netstat this is looking like this:
tcp  0 0 0.0.0.0:59247 0.0.0.0:*  LISTEN      28233/gst
tcp  0 0 127.0.0.1:8080 0.0.0.0:* LISTEN      28233/gst

and on strace:
socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 6
rt_sigprocmask(SIG_BLOCK, ~[QUIT ILL ABRT BUS SEGV RTMIN RT_1], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
... too many of these...
setsockopt(6, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(6, {sa_family=AF_INET, sin_port=htons(8080),
sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EADDRINUSE (Address already in use)

getsockopt(6, SOL_SOCKET, SO_ERROR, [0], [4]) = 0

getsockname(6, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr("0.0.0.0")}, [16]) = 0

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: TCP Server Socket issue

Paolo Bonzini-2
On 01/16/2011 11:34 PM, Holger Hans Peter Freyther wrote:
>  From a quick look at the socket/ipv4/ipv6 impl I don't see anyone assigning
> sk_err to anything in case of a failed bind, so I am not sure where the
> SO_ERROR != 0 on failed bind is coming from.

FWIW I don't understand even where is that connect sets sk_err in the
Linux socket code...  However I think accept is safe because it may be a
blocking call.

We need testcases and I like your start.  I didn't merge it yet, but I
like your way to prod. :)

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk