close(2) while accept(2) is blocked

Andriy Gapon avg at FreeBSD.org
Thu Apr 4 17:43:21 UTC 2013


on 01/04/2013 18:22 John Baldwin said the following:
> I think you need to split the 'struct file' reference count into two different
> counts similar to the how we have vref/vrele vs vhold/vdrop for vnodes.  The
> fget for accept and probably most other system calls should probably be equivalent
> to vhold, whereas things like open/dup (and storing an fd in a cmsg) should be
> more like vref.  close() should then be a vrele().

This model makes perfect sense.
Unfortunately, ENOTIME to work on this.

Meanwhile I am using the following patch specific to local domain sockets,
accept(2) and shutdown(2).  Turns out that the problematic application does both
shutdown(RDWR) and close(2), but that doesn't help on FreeBSD.
BTW, this is the application:
http://thread.gmane.org/gmane.os.freebsd.devel.office/1754
The patch does help.

Author: Andriy Gapon <avg at icyb.net.ua>
Date:   Thu Mar 28 20:08:13 2013 +0200

    [test!] uipc_shutdown: use soisdisconnected instead of socantsendmore

    So that in addition to disabling sends we also wake up threads blocked
    in accept (on so_timeo in general).

diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 9b60eab..e93d46c 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1074,7 +1074,7 @@ uipc_shutdown(struct socket *so)

 	UNP_LINK_WLOCK();
 	UNP_PCB_LOCK(unp);
-	socantsendmore(so);
+	soisdisconnected(so);
 	unp_shutdown(unp);
 	UNP_PCB_UNLOCK(unp);
 	UNP_LINK_WUNLOCK();


-- 
Andriy Gapon


More information about the freebsd-net mailing list