Results 1 to 2 of 2

Thread: Socket bind error

  1. #1

    Default Socket bind error

    I have a program that has been in the field for over a year now. Once in awhile I get a call that it is not working and when I take a look it is because the program is getting a report that the socket is bound to another process. I have put in code to try and capture shutdown events and close the socket more gracefully and this has helped.

    It seem that the qtsocket class must be spawning another process that binds the listner. When the main program dies this phantom process is still there tying up the socket resource. You can query the OS and sure enough it thinks there is a process attached but can't tell you what is attached.

    I've seen the posts that talk about setting the address for resuse, that's fine but it looks to be a bug in the qtsocket class. There is a companion program that uses native socket binding and it never has this problem.

    I have experienced this problem on both Unix and Linux OS with UNIX seeming to be more prone to the problem.

    Anyone who thinks they have dealt with this succesfully I would love to hear form you. This problem has been plaguing me for a year now.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Socket bind error

    Quote Originally Posted by rburge View Post
    It seem that the qtsocket class must be spawning another process that binds the listner. When the main program dies this phantom process is still there tying up the socket resource. You can query the OS and sure enough it thinks there is a process attached but can't tell you what is attached.
    No, it's nothing like that. It is the operating system that disallows to bind to a socket which has been ungracefully closed a while earlier. This is to prevent a situation where a new process that binds to the socket receives stale data that should have been received by the old process (take into consideration the fact that if a process dies, the other side of connection is not aware of that and might try transmitting some data).

    I've seen the posts that talk about setting the address for resuse, that's fine but it looks to be a bug in the qtsocket class.
    Qt sockets have nothing to do with it.
    There is a companion program that uses native socket binding and it never has this problem.
    The companion program must be preventing the default behaviour then. Try a simple program that calls socket(), bind(), listen(), accept() and then kill the process and try restarting it. You'll see that the bind fails. Or look into Qt sources to see how the socket is implemented - it calls native bind().

    I have experienced this problem on both Unix and Linux OS with UNIX seeming to be more prone to the problem.
    As I said, it's not a problem, it's a failsafe.

    Anyone who thinks they have dealt with this succesfully I would love to hear form you. This problem has been plaguing me for a year now.
    The simplest solution is to improve your application so that it doesn't crash Or just set SO_REUSE on the socket as advised.

Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.