kern/159179: [libc] close(2) emitting ECONNRESET is not POSIX compliant

Michael Gmelin freebsd at
Mon Jul 25 10:10:08 UTC 2011

>Number:         159179
>Category:       kern
>Synopsis:       [libc] close(2) emitting ECONNRESET is not POSIX compliant
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 25 10:10:07 UTC 2011
>Originator:     Michael Gmelin
>Release:        FreeBSD 8.2-RELEASE-p1
Grem Equity GmbH
System: FreeBSD srv06 8.2-RELEASE-p1 FreeBSD 8.2-RELEASE-p1 #0 r221593: Sat May  7 15:12:25 CEST 2011
With the advent of FreeBSD 6.3 the close(2) call was changed to return errno ECONNRESET under certain circumstances. The man page was changed accordingly, but in my understanding errno = ECONNRESET is not covered by POSIX.1-2008 (see Also all other implementations of close I've seen in the past do not behave like this, which leads to actual problems in reality.

In practice this means that all projects ported to FreeBSD would need to get reviewed if they can handle these situations gracefully, which usually doesn't happen. Examples I'm aware of are:



The problematic change was done quite a while ago:

r164516 | sam | 2006-11-22 17:16:54 +0000 (Wed, 22 Nov 2006) | 19 lines

Change error codes returned by protocol operations when an inpcb is
o return ECONNRESET instead of EINVAL for close, disconnect, shutdown,
  rcvd, rcvoob, and send operations
o return ECONNABORTED instead of EINVAL for accept

These changes should reduce confusion in applications since EINVAL is
normally interpreted to mean an invalid file descriptor.  This change
does not conflict with POSIX or other standards I checked. The return
of EINVAL has always been possible but rare; it's become more common
with recent changes to the socket/inpcb handling and with finer-grained
locking and preemption.

Note: there are other instances of EINVAL for this state that were
      left unchanged; they should be reviewed.

Reviewed by:    rwatson, andre, ru
MFC after:      1 month


There are other open PRs out there (e.g. but these don't focus on the POSIX impact of this behavior. Also note that other calls might be affected by this as well (as suggested by the commit message).


Make sure, that the close call conforms to POSIX.1-2008 (by returning EINVAL instead of ECONNRESET again).

Please note that this probably won't fix the underlying problem - we started seeing these ECONNRESET issues on machines with eight and more cores quite frequently (using ice). So just replacing ECONNRESET with EINVAL, but not fixing why this is happening will probably lead to more confusion and break the workarounds that are out there right now.


More information about the freebsd-bugs mailing list