Bug 196035 - Subsequent connect on ready socket returns EINVAL instead of ECONNREFUSED
Summary: Subsequent connect on ready socket returns EINVAL instead of ECONNREFUSED
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.1-RELEASE
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Julien Charbon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-16 19:10 UTC by Mark Nunberg
Modified: 2015-05-15 12:41 UTC (History)
4 users (show)

See Also:


Attachments
Sample program to reproduce (1.29 KB, text/plain)
2014-12-16 19:10 UTC, Mark Nunberg
no flags Details
Patch to fix socket errors to match POSIX (1.80 KB, patch)
2014-12-16 23:23 UTC, Harrison Grundy
no flags Details | Diff
Updated Patch to return EADDRINUSE on TIME_WAIT instead of EALREADY (1.45 KB, patch)
2014-12-17 00:39 UTC, Harrison Grundy
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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 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 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