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:
Created attachment 150658 [details] Patch to fix socket errors to match POSIX
Created attachment 150662 [details] Updated Patch to return EADDRINUSE on TIME_WAIT instead of EALREADY
I can verify the patch fixes the issue
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)
Fix pushed here: https://svnweb.freebsd.org/base?view=revision&revision=279821
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