Date: Mon, 25 Jul 2011 10:06:12 GMT From: Michael Gmelin <freebsd@grem.de> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/159179: [libc] close(2) emitting ECONNRESET is not POSIX compliant Message-ID: <201107251006.p6PA6CbU019245@red.freebsd.org> Resent-Message-ID: <201107251010.p6PAA7nW088115@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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 >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jul 25 10:10:07 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Michael Gmelin >Release: FreeBSD 8.2-RELEASE-p1 >Organization: Grem Equity GmbH >Environment: System: FreeBSD srv06 8.2-RELEASE-p1 FreeBSD 8.2-RELEASE-p1 #0 r221593: Sat May 7 15:12:25 CEST 2011 >Description: 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 http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html). 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: Ruby: http://redmine.ruby-lang.org/issues/3515 Ice: http://www.zeroc.com/forums/patches/5435-patch-network-cpp-freebsd-econnreset-close-2-problem.html 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 marked INP_DROPPED or INP_TIMEWAIT: 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. http://www.freebsd.org/cgi/query-pr.cgi?pr=146845) 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). >How-To-Repeat: >Fix: 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. >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107251006.p6PA6CbU019245>