Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22235

Socket Error : Address still in use (Conveting from python 1.5.2 to 2.7.1)

From Wong Wah Meng-R32813 <r32813@freescale.com>
Subject Socket Error : Address still in use (Conveting from python 1.5.2 to 2.7.1)
Date 2012-03-27 09:41 +0000
References <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.1035.1332845840.3037.python-list@python.org> (permalink)

Show all headers | View raw


Hello there,

I am in the midst of converting my application from python 1.5.2 to python 2.7.1 on HP-UX 11 Itanium box. 

My application server will set a listening port, accepting request from multiple clients. The code just works fine in the old python environment. E.g. when I do a lsof | grep <listening port> I got the following.

python     62602  genasm    5u  IPv4 0x7350d1f0        0t0  TCP zmy02aix02:12121 (LISTEN)
python     62602  genasm    6u  IPv4 0x744fb5f0        0t0  TCP zmy02aix02:12121->zmy02aix02-bkup:51867 (ESTABLISHED)
python     62602  genasm    7u  IPv4 0x75b959f0        0t0  TCP zmy02aix02:12121->zmy02aix02-bkup:51869 (ESTABLISHED)
python     62602  genasm    8u  IPv4 0x75a559f0        0t0  TCP zmy02aix02:12121->zmy02aix02-bkup:51873 (ESTABLISHED)

Strange things happened in python 2.7.1. Without modifying the code of how the socket was created and how the TCP/IP address was bound to the socket, it seems that every other processes that I run, which supposed to connect to the listening port as a client program, also appears to be holding a listening port. This is weird. Anyone has encountered this before especially when you were converting from an old python to a new python? Like you can see below there are 5 processes hosting the listening port of 18882.

$ lsof -i tcp | grep 18882
python  10598 r32813    3u  IPv4 0xe00000050b73e400       0t0  TCP zmy02hp3.ap.freescale.net:18882 (LISTEN)
python  18181 r32813    3u  IPv4 0xe00000050b73e400       0t0  TCP zmy02hp3.ap.freescale.net:18882 (LISTEN)
python  20025 r32813    3u  IPv4 0xe00000050b73e400       0t0  TCP zmy02hp3.ap.freescale.net:18882 (LISTEN)
python  26295 r32813    3u  IPv4 0xe00000050b73e400       0t0  TCP zmy02hp3.ap.freescale.net:18882 (LISTEN)
python  26428 r32813    3u  IPv4 0xe00000050b73e400       0t0  TCP zmy02hp3.ap.freescale.net:18882 (LISTEN)

Since only one of them is the genuine process holding the port, I need to kill off the rest of the process if I need to restart the genuine process running under that port. It should not work this way. 

Here is the code of the application process that hosts the listening port. 

	self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
	self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
	self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1
	self.sock.setsockopt( socket.IPPROTO_TCP, _TCP_NODELAY, 1 )
	self.sock.bind( self.server_address )
  

Here is the client code that does the connection.

       self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
       self.sock.setsockopt( socket.IPPROTO_TCP, _TCP_NODELAY, 1 )
       self.sock.connect( self.server_address )

Regards,
Wah Meng

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-03-26 19:42 -0700
  Re: OAuth 2.0 implementation Ben Finney <ben+python@benfinney.id.au> - 2012-03-27 14:11 +1100
    Re: OAuth 2.0 implementation Roy Smith <roy@panix.com> - 2012-03-26 23:30 -0400
      Re: OAuth 2.0 implementation Ben Finney <ben+python@benfinney.id.au> - 2012-03-27 14:49 +1100
        Re: OAuth 2.0 implementation Roy Smith <roy@panix.com> - 2012-03-26 23:57 -0400
          Re: OAuth 2.0 implementation Ben Finney <ben+python@benfinney.id.au> - 2012-03-27 15:24 +1100
            Re: OAuth 2.0 implementation Jack Diederich <jackdied@gmail.com> - 2012-03-27 01:24 -0400
            Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-03-26 22:30 -0700
              Re: OAuth 2.0 implementation Roy Smith <roy@panix.com> - 2012-03-27 10:18 -0400
                Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-03-27 10:54 -0700
                Re: OAuth 2.0 implementation Mark Hammond <skippy.hammond@gmail.com> - 2012-03-28 14:42 +1100
    Re: OAuth 2.0 implementation Stuart Bishop <stuart@stuartbishop.net> - 2012-03-27 16:59 +0700
    Socket Error : Address still in use  (Conveting from python 1.5.2 to 2.7.1) Wong Wah Meng-R32813 <r32813@freescale.com> - 2012-03-27 09:41 +0000
    Re: OAuth 2.0 implementation Roland Hedberg <roland@catalogix.se> - 2012-03-27 15:36 +0200
  Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-07-05 07:06 -0700
    Re: OAuth 2.0 implementation Alec Taylor <alec.taylor6@gmail.com> - 2012-07-06 01:19 +1000
      Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-07-05 10:48 -0700
      Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-07-05 10:48 -0700
        Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-07-06 08:38 -0700
        Re: OAuth 2.0 implementation Demian Brecht <demianbrecht@gmail.com> - 2012-07-06 08:38 -0700
          Re: OAuth 2.0 implementation Alec Taylor <alec.taylor6@gmail.com> - 2012-07-07 04:41 +1000
          RE: OAuth 2.0 implementation "Demian Brecht" <demianbrecht@gmail.com> - 2012-07-06 11:49 -0700
          Re: OAuth 2.0 implementation Alec Taylor <alec.taylor6@gmail.com> - 2012-07-07 04:58 +1000

csiph-web