title: How to deal with ECONNREFUSED for connect?
body: <p>We have a process hanging, and the truss shows it also tries to connect but failed with error ECONNREFUSED. 
  The man page says the following, but why it got rejected again and again? </p>
  
  <pre><code> ECONNREFUSED            The attempt to  connect  was  force-
                           fully  rejected. The calling program
                           should close(2) the socket  descrip-
                           tor,      and      issue     another
                           socket(3SOCKET) call to obtain a new
                           descriptor before attempting another
                           connect() call.
  </code></pre>
  
  <p>truss -p 2145 </p>
  
  <p>/3:     lwp_park(0x00000000, 0)         (sleeping...)</p>
  
  <p>/2:     nanosleep(0xFFFFFFFF7B5FBE60, 0xFFFFFFFF7B5FBE50) (sleeping...)</p>
  
  <p>/2:     nanosleep(0xFFFFFFFF7B5FBE60, 0xFFFFFFFF7B5FBE50) = 0</p>
  
  <p>/2:     so_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP, "", SOV_DEFAULT) = 17</p>
  
  <p>/2:     fcntl(17, F_SETFD, 0x00000001)                  = 0</p>
  
  <p>/2:     connect(17, 0xFFFFFFFF7B5FBF40, 16, SOV_DEFAULT) Err#146 ECONNREFUSED</p>
  
  <p>/2:     close(17)                                       = 0</p>
  
  <p>/2:     nanosleep(0xFFFFFFFF7B5FBE60, 0xFFFFFFFF7B5FBE50) (sleeping...)</p>
  
  <p>/2:     nanosleep(0xFFFFFFFF7B5FBE60, 0xFFFFFFFF7B5FBE50) = 0</p>
  
  <p>/2:     so_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP, "", SOV_DEFAULT) = 17</p>
  
  <p>/2:     fcntl(17, F_SETFD, 0x00000001)                  = 0</p>
  
  <p>/2:     connect(17, 0xFFFFFFFF7B5FBF40, 16, SOV_DEFAULT) Err#146 ECONNREFUSED</p>
  
  <p>/2:     close(17)                                       = 0</p>
  
  <p>/2:     nanosleep(0xFFFFFFFF7B5FBE60, 0xFFFFFFFF7B5FBE50) (sleeping...)</p>