From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#56002: src/process.c; make-process fails to clean up stderr process on early exit Date: Thu, 11 Aug 2022 09:30:53 +0300 Message-ID: <83v8qzpa02.fsf@gnu.org> References: <83pmj9qjgk.fsf@gnu.org> <8735e70xwl.fsf@gnus.org> <831qtrvtg5.fsf@gnu.org> <83czd9ve0n.fsf@gnu.org> <8335e4q8gm.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13248"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 56002@debbugs.gnu.org To: Tom Gillespie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 11 08:32:37 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oM1kD-0003Ll-7o for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Aug 2022 08:32:37 +0200 Original-Received: from localhost ([::1]:57428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oM1kC-0005bF-5f for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Aug 2022 02:32:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oM1jf-0005ZC-2i for bug-gnu-emacs@gnu.org; Thu, 11 Aug 2022 02:32:13 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oM1je-0000j9-HL for bug-gnu-emacs@gnu.org; Thu, 11 Aug 2022 02:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oM1je-0005CA-DZ for bug-gnu-emacs@gnu.org; Thu, 11 Aug 2022 02:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Aug 2022 06:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56002 X-GNU-PR-Package: emacs Original-Received: via spool by 56002-submit@debbugs.gnu.org id=B56002.166019947519896 (code B ref 56002); Thu, 11 Aug 2022 06:32:02 +0000 Original-Received: (at 56002) by debbugs.gnu.org; 11 Aug 2022 06:31:15 +0000 Original-Received: from localhost ([127.0.0.1]:51232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oM1is-0005Aq-Mo for submit@debbugs.gnu.org; Thu, 11 Aug 2022 02:31:15 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oM1io-0005AX-8y for 56002@debbugs.gnu.org; Thu, 11 Aug 2022 02:31:12 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:47482) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oM1ii-0000ez-Vq; Thu, 11 Aug 2022 02:31:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=D5ERYI/yGet7EBy2qBaibP0fROuKPKtpfQ28LSUJh2E=; b=VN/Gfqmxaciy PhULRctXSFpsnjbkjD26hYAD8OHntBUlUxNYi3qfrrHDXQ0CEWpyadp8m3TADdiCsMRhIwajSBXBa LMuCRrUJ6yXNPNSNgalBVb8rlm7vCVZucLlcBVQXAsbC60p9aZLSYQVR8SMqGyeSLpIlol2zFJ1wX z4gDtR9WhayuT/GI+WDuj1NnQ2RSD1iwuxsgk+jMivzaHku+Zwx4jUN+f9JdC4lTKYPHcJwAmSmBs gi2D/91C09Ojoj02iztJwcTr4B1DbXiUjYwd3zZkjRzPF9wh3d1EvdW40Z8C+qVNYCg1pLDM2Q/A2 Cj7mp6hlQzbHtQwHEEA9wA==; Original-Received: from [87.69.77.57] (port=1570 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oM1if-00024a-Jx; Thu, 11 Aug 2022 02:31:02 -0400 In-Reply-To: (message from Tom Gillespie on Wed, 10 Aug 2022 19:33:22 -0700) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:239331 Archived-At: > From: Tom Gillespie > Date: Wed, 10 Aug 2022 19:33:22 -0700 > Cc: larsi@gnus.org, 56002@debbugs.gnu.org > > So I realized that the current patch only fixes half the problems > but it does fix them completely. > > Your concerns are well founded but are only relevant to the half > of the problems that this patch does not fix (more detail below). > > Thus, this patch can be merged as is and a separate patch > that uses unwind protect is needed to deal with failures that > happen inside create_process. An additional test is needed > for that as well since the current test only triggers a failure > in Fmake_process prior to the call to create process. I'd prefer to have all the cleanup in an unwind function, if that's possible, because that would allow us not to rearrange the existing code, and thus would be free of the potential risks I'm worried about. We could have more than a single unwind function if that is required. > Ideally the existing patches would be merged and I will submit > another one with the fix for issues in create_process. The function > used in unwind protectis going to be more complex and will need > more review so we should not hold up the existing patch to wait > for that one. I'm not bothered with reviewing complex unwind functions, because their code is local: we need to review that code without thinking about anything that's not in it. > > Maybe I'm misunderstand something here, but the usual way of doing > > that is to use record_unwind_protect immediately after creating the > > stderr process, with a suitable unwind function that would perform the > > necessary cleanup. This ensures that however we exit make-process, > > the cleanup is never missed, and we don't leak resources. > > > > Why cannot we do this here? What am I missing? > > We could but do not need to for the issues inside Fmake_process > since we can avoid writing any new code and move the call to > Fmake_pipe_process to immediately before the call to create_process. As I explained earlier, I'd prefer not to move the code we already have. Thus, basing the cleanups on unwind function is from my POV preferable. > There is no risk of unexpected interactions with os conventions > prior to the call to create_process. Opening file descriptors and creating Lisp objects in a different sequence also affects the OS interactions, either indirectly or directly. > For any error happening in create_process before a successful return > from emacs_spawn we do need to use record unwind protect. The > function needed to do that cleanup safely is not as simple and > should be in an independent patch that can be reviewed separately. How about two separate patches, but both based on unwind function(s) without moving any existing code? You could make the unwind function for the first patch simple, and then complicate it in the second patch. Thanks.