Error Binding Socket Address Already In Use
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this bind failed. error address already in use site About Us Learn more about Stack Overflow the company Business Learn
Error Binding Socket Addr='af_unix(/dev/log)' Error='address Already In Use (98)'
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question pgpool bind socket failed with error address already in use x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Python:
Could Not Bind Socket Address Already In Use
Binding Socket: “Address already in use” up vote 37 down vote favorite 10 I have a question regarding client socket on TCP/IP network. Let's say I use try: comSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) comSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) except socket.error, msg: sys.stderr.write("[ERROR] %s\n" % msg[1]) sys.exit(1) try: comSocket.bind(('', 5555)) comSocket.connect() except socket.error, msg: sys.stderr.write("[ERROR] %s\n" % msg[1]) sys.exit(2) The socket created will be bound to port 5555. can't bind server socket address already in use The problem is that after ending the connection comSocket.shutdown(1) comSocket.close() Using wireshark, I see the socket closed with FIN,ACK and ACK from both sides, I can't use the port again. I get the following error: [ERROR] Address already in use I wonder how can I clear the port right away so that next time I still can use that same port. comSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) setsockopt doesn't seem to be able to resolve the problem Thank you! python sockets tcp port share|improve this question edited Dec 31 '13 at 19:49 asked Jun 17 '11 at 0:12 Tu Hoang 95872235 Why does a client need a specific port? –AJ. Jun 17 '11 at 0:17 Because I have to put that into a production server, and in that server, all outgoing connections are blocked. I need to specify a specific port to the socket so that they can set up a rule on the firewalls that allows the connection to go through. –Tu Hoang Jun 17 '11 at 0:46 I suggest you copy & paste the actual code. What you wrote above has an obvious e
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Error Binding Socket Addr='af_inet
Overflow the company Business Learn more about hiring developers or posting ads with us
Error Binding Socket (3420)
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a how to use so_reuseaddr community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Socket error: Address already in use up vote 2 down vote favorite 4 I have http://stackoverflow.com/questions/6380057/python-binding-socket-address-already-in-use a CherryPy script that I frequently run to start a server. Today I was having to start and stop it a few times to fix some bugs in a config file, and I guess the socket didn't close all the way because when I tried to start it up again I got this issue: [23/Mar/2015:14:08:00] ENGINE Listening for SIGHUP. [23/Mar/2015:14:08:00] ENGINE Listening for SIGTERM. [23/Mar/2015:14:08:00] ENGINE Listening for SIGUSR1. [23/Mar/2015:14:08:00] ENGINE http://stackoverflow.com/questions/29217502/socket-error-address-already-in-use Bus STARTING CherryPy Checker: The Application mounted at '' has an empty config. [23/Mar/2015:14:08:00] ENGINE Started monitor thread 'Autoreloader'. [23/Mar/2015:14:08:00] ENGINE Started monitor thread '_TimeoutMonitor'. [23/Mar/2015:14:08:00] ENGINE Error in HTTP server: shutting down Traceback (most recent call last): File "/home/andrew/virtualenvs/mikernels/lib/python2.7/site-packages/cherrypy/process/servers.py", line 188, in _start_http_thread self.httpserver.start() File "/home/andrew/virtualenvs/mikernels/lib/python2.7/site-packages/cherrypy/wsgiserver/wsgiserver2.py", line 1848, in start raise socket.error(msg) error: No socket could be created I edited CherryPy's wsgiserver2.py to see the details of the socket.error and error.strerror was 98 (98, 'Address already in use') Address already in use Meanwhile my socket is constructed as: af = 2 socktype = 1 proto = 6 canonname = '' sa = ('0.0.0.0', 2112) self.bind(af, socktype, proto) (that's not exact code but that's what the values are when the error is fired) I checked netstat and didn't see anything listening on port 2112, what could be causing the problem and how can I go about diagnosing it? Thanks! python sockets cherrypy share|improve this question asked Mar 23 '15 at 18:16 Andrew Latham 1,97572259 add a comment| 3 Answers 3 active oldest votes up vote 8 down vote accepted You can try the following from socket import * sock=socket() sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # then bind From the docs: The SO_REUSEADDR flag tells the kernel to reuse a local socket in TIME_WAIT
and both ends must ACK (acknowledge) each other's FIN packets. The FIN packets are initiated by the application performing a close(), a shutdown(), or an exit(). The ACKs are handled by the kernel after the close() has completed. Because http://hea-www.harvard.edu/~fine/Tech/addrinuse.html of this, it is possible for the process to complete before the kernel has released the http://askubuntu.com/questions/447820/ssh-l-error-bind-address-already-in-use associated network resource, and this port cannot be bound to another process until the kernel has decided that it is done. Figure 1 Figure 1 shows all of the possible states that can occur during a normal closure, depending on the order in which things happen. Note that if you initiate closure, there is a TIME_WAIT state that is absent from the other side. address already This TIME_WAIT is necessary in case the ACK you sent wasn't received, or in case spurious packets show up for other reasons. I'm really not sure why this state isn't necessary on the other side, when the remote end initiates closure, but this is definitely the case. TIME_WAIT is the state that typically ties up the port for several minutes after the process has completed. The length of the associated timeout varies on different operating systems, and may be dynamic address already in on some operating systems, however typical values are in the range of one to four minutes. If both ends send a FIN before either end receives it, both ends will have to go through TIME_WAIT. Normal Closure of Listen Sockets A socket which is listening for connections can be closed immediately if there are no connections pending, and the state proceeds directly to CLOSED. If connections are pending however, FIN_WAIT_1 is entered, and a TIME_WAIT is inevitable. Note that it is impossible to completely guarantee a clean closure here. While you can check the connections using a select() call before closure, a tiny but real possibility exists that a connection could arrive after the select() but before the close(). Abnormal Closure If the remote application dies unexpectedly while the connection is established, the local end will have to initiate closure. In this case TIME_WAIT is unavoidable. If the remote end disappears due to a network failure, or the remote machine reboots (both are rare), the local port will be tied up until each state times out. Worse, some older operating systems do not implement a timeout for FIN_WAIT_2, and it is possible to get stuck there forever, in which case restarting your server could require a reboot. If the local application dies while a connection is active, the port will be tied up in TIME_WAIT. This is also true if the application dies while a connection is pending. Str
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top ssh -L (error: bind: Address already in use) up vote 9 down vote favorite 5 Pretty simple, I know that this has happened to me before. Couldn't find a good answer on AU. I was running an ssh session with ports bound: ssh -L 3000: