From owner-cvs-all@FreeBSD.ORG Tue Feb 21 02:49:59 2006 Return-Path: X-Original-To: cvs-all@FreeBSD.org Delivered-To: cvs-all@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B57DF16A420; Tue, 21 Feb 2006 02:49:59 +0000 (GMT) (envelope-from mux@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 84DC643D45; Tue, 21 Feb 2006 02:49:59 +0000 (GMT) (envelope-from mux@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k1L2nxBq079879; Tue, 21 Feb 2006 02:49:59 GMT (envelope-from mux@repoman.freebsd.org) Received: (from mux@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k1L2nxtU079878; Tue, 21 Feb 2006 02:49:59 GMT (envelope-from mux) Message-Id: <200602210249.k1L2nxtU079878@repoman.freebsd.org> From: Maxime Henrion Date: Tue, 21 Feb 2006 02:49:59 +0000 (UTC) To: projects-committers@FreeBSD.org, cvs-projects@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Cc: Subject: cvs commit: projects/csup mux.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Feb 2006 02:49:59 -0000 mux 2006-02-21 02:49:59 UTC FreeBSD projects repository Modified files: csup mux.c Log: Fix a race related to the multiplexer shutdown. Since mux_shutdown() needs to unlock the multiplexer mutex to cancel the sender and receiver threads and that it was setting the "closed" status before unlocking, another thread calling mux_shutdown() could return immediately, even though the other thread doing the shutdown has not finished cancelling the threads. The net effect to this race was that if the receiver thread got his connection closed and thus called mux_shutdown(), it would wake up the worker threads and, in turn, the main thread waiting on them, and the main thread would eventually call mux_close() before the receiver thread has finished killing the sender one, freeing the multiplexer data structures under its feet. To fix this, have both a "closing" and a "closed" flag. The "closing" flag means that someone is taking care of the shutdown, but he has not finished it. The "closed" flag means the multiplexer is really closed now. If a thread calls mux_shutdown() while the multiplexer is in the "closing" state, it will wait on the "done" condition variable so that it don't return before the multiplexer is fully closed. And if we are the thread doing the shutdown, we relock the multiplexer, set the "closed" flag and signal the waiting threads only when we are done killing the threads. Revision Changes Path 1.66 +17 -2 projects/csup/mux.c