Bug 196035

Summary: Subsequent connect on ready socket returns EINVAL instead of ECONNREFUSED
Product: Base System Reporter: Mark Nunberg <mnunberg>
Component: kernAssignee: Julien Charbon <jch>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, harrison.grundy, jch, jhb
Priority: ---    
Version: 10.1-RELEASE   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
Sample program to reproduce
none
Patch to fix socket errors to match POSIX
none
Updated Patch to return EADDRINUSE on TIME_WAIT instead of EALREADY none

Description Mark Nunberg 2014-12-16 19:10:07 UTC
Created attachment 150652 [details]
Sample program to reproduce

EINVAL is not a documented return code for these situations. Furthermore, the expected error code, ECONNREFUSED is not returned. If i call getsockopt(s, SOL_SOCKET, SO_ERROR, ...) _before_ the next connect, i indeed get 'ECONNREFUSED' in the error.

Sample program attached:
Comment 1 Harrison Grundy 2014-12-16 23:23:13 UTC
Created attachment 150658 [details]
Patch to fix socket errors to match POSIX
Comment 2 Harrison Grundy 2014-12-17 00:39:47 UTC
Created attachment 150662 [details]
Updated Patch to return EADDRINUSE on TIME_WAIT instead of EALREADY
Comment 3 Mark Nunberg 2014-12-17 16:04:37 UTC
I can verify the patch fixes the issue
Comment 4 John Baldwin freebsd_committer freebsd_triage 2015-01-13 21:10:43 UTC
You might want to rope in jch@ as well as this sounds orthogonal to https://svnweb.freebsd.org/base?view=revision&revision=273014 (though not identical)
Comment 5 Julien Charbon freebsd_committer freebsd_triage 2015-03-09 20:35:04 UTC
Fix pushed here: https://svnweb.freebsd.org/base?view=revision&revision=279821
Comment 6 commit-hook freebsd_committer freebsd_triage 2015-05-15 12:35:41 UTC
A commit references this bug:

Author: jch
Date: Fri May 15 12:35:19 UTC 2015
New revision: 282968
URL: https://svnweb.freebsd.org/changeset/base/282968

Log:
  MFC r279821:

      In TCP, connect() can return incorrect error code EINVAL
      instead of EADDRINUSE or ECONNREFUSED

      PR:                         196035
      Differential Revision:      https://reviews.freebsd.org/D1982
      Reported by:                Mark Nunberg <mnunberg@haskalah.org>
      Submitted by:               Harrison Grundy <harrison.grundy@astrodoggroup.com>
      Reviewed by:                adrian, jch, glebius, gnn
      Approved by:                jhb

Changes:
_U  stable/10/
  stable/10/sys/netinet/tcp_usrreq.c