From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iJXqBrAqRmCbNAAA0tVLHw (envelope-from ) for ; Mon, 08 Mar 2021 13:46:24 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 4KKxArAqRmATZAAAB5/wlQ (envelope-from ) for ; Mon, 08 Mar 2021 13:46:24 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5184B1AD99 for ; Mon, 8 Mar 2021 14:46:23 +0100 (CET) Received: from localhost ([::1]:57092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJGDG-0002cW-5W for larch@yhetil.org; Mon, 08 Mar 2021 08:46:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJGCx-0002b1-IP for bug-guix@gnu.org; Mon, 08 Mar 2021 08:46:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:59084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJGCv-0007Iy-TR for bug-guix@gnu.org; Mon, 08 Mar 2021 08:46:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lJGCv-00024o-SE for bug-guix@gnu.org; Mon, 08 Mar 2021 08:46:01 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#46796: Cuirass & pointer finalization. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Mon, 08 Mar 2021 13:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46796 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Mathieu Othacehe Received: via spool by 46796-submit@debbugs.gnu.org id=B46796.16152111287938 (code B ref 46796); Mon, 08 Mar 2021 13:46:01 +0000 Received: (at 46796) by debbugs.gnu.org; 8 Mar 2021 13:45:28 +0000 Received: from localhost ([127.0.0.1]:42397 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJGCO-00023y-5F for submit@debbugs.gnu.org; Mon, 08 Mar 2021 08:45:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJGCM-00023m-Op for 46796@debbugs.gnu.org; Mon, 08 Mar 2021 08:45:27 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47348) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJGCF-0006yT-N0 for 46796@debbugs.gnu.org; Mon, 08 Mar 2021 08:45:21 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=41010 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lJGCC-00030c-AY; Mon, 08 Mar 2021 08:45:16 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <8735xihq60.fsf@gnu.org> <87ft1hvfm4.fsf@gnu.org> <87k0qrusde.fsf@gnu.org> <87mtvmnfjb.fsf@gnu.org> <87blc1oeba.fsf@gnu.org> <87im69bia7.fsf@gnu.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 18 =?UTF-8?Q?Vent=C3=B4se?= an 229 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Mon, 08 Mar 2021 14:45:14 +0100 In-Reply-To: <87im69bia7.fsf@gnu.org> (Mathieu Othacehe's message of "Tue, 02 Mar 2021 18:02:40 +0100") Message-ID: <87v9a1ep3p.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 46796@debbugs.gnu.org Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615211183; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=5U0Jbo1EGwrONDm2g0UeJVVeoEe3dT+bxIdjTSSInyA=; b=UL5H1zlflJddkIEKZQnRWnEoPi4dpXugJ6Y/aXcO3Y8kpxwjFUps+/skVYpe7tgax+NDIU MvCG3IIlO2+ESxDXR5QogqpSaEKz0N5kOp2edsLUXvpSO7ryCEzEyh4BWwlfyaVkiJs6NU /SKBPz4UYPn4LG4PbnwqKLOvhbVnIz92qyRrOZbHGz3ZxQ5Z+rHQK2/fUWqMgCeTP0knXH wcPfbgSroWzwIbwI/aGOfg2YCxihhbR6kQZsUw6tcnvEZag43iFYcHt/FeXqyYAjPXqh73 K6y019nzsjlGtcfpSu1lt8wV1WuCbNIFlffJ4yow1nfSJVwgg2bYjDzP1OWp6Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615211183; a=rsa-sha256; cv=none; b=E+QX1IgIKYoohgphQqxC2U85UxncrqrZpihQVB4IEPKkpzCZmLAMxb9o7U40pd03+SCIti uMujzkO8Q8zFPrI6+HtwH/e0ZTRDKgEqJiCdt2n3jKDN4akzicjBUmiH4Un71EqBjSYwRJ DOCR5AyjCdFXRZbQNVu1DLg1H8iOsSlkwub5RVxyDjvgruRHrCxmrZSu5QlMHdDJ1cYz2r VdcSKUGrjFVs/iBHYXHrpBZpaKGcnQQ+FEQtQCbkByK/WO1yIxozVWW1hCZXTtX3YZtB6T WVxdL5FsB7RnwmLFE5R7I7OYS5LCo1aDGzG/MuoS9SXNk4kyLQPsIJpKQfLFoQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Spam-Score: -2.88 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 5184B1AD99 X-Spam-Score: -2.88 X-Migadu-Scanner: scn0.migadu.com X-TUID: ll6bgiVzMj8t Hi, Mathieu Othacehe skribis: >> Hmm I think the bytevector and the pointer object can be finalized in >> the same GC cycle; when that happens, you have no guarantee as to the >> order in which they are finalized. > > That would explain the crashes indeed. > >> But=E2=80=A6 is it really similar to your ZMQ issue? There you had mess= age >> object wrappers (as per =E2=80=98define-wrapped-pointer-type=E2=80=99) a= nd a pointer >> object to the underlying C object, right? > > I think the only difference is that the reproducer doesn't introduce the > wrapped pointer object. Using ZMQ, the message creation looks like: > > zmq-msg-init > Bytevector creation with make-bytevector at address P > Bytevector initialization with zmq_msg_init(P) > Install zmq_msg_close as finalizer on P > Message wrapping using (pointer->message P) > Return the wrapped message Shouldn=E2=80=99t the finalizer be on , then? > The user can then operate on the wrapped message by passing it to other > message API procedures such as zmq-message-size. Those procedures will > call ZMQ using the underlying pointer. > > The bytevector/pointer object undetermined GC order is really > problematic then. I'm not sure why I'm not experiencing this crash using > Guardians since they are also using finalizers. Guardians =E2=80=9Crevive=E2=80=9D objects: when you call the guardian, it = returns the object that _would have_ been GC=E2=80=99d. IOW, guardians delay =E2=80=9C= actual=E2=80=9D finalization. That may be the explanation. > The ultimate work around would be to leave the message closing > responsibility to the user but that would be sad. Yeah, don=E2=80=99t do that. :-) > Do you know if there's another to prevent the bytevector from being > collected before the pointer object? I=E2=80=99d really need to dive into the code but I=E2=80=99m confident the= re=E2=80=99s nothing special about this scenario; we=E2=80=99re probably just overlooking some pointer ownership rule. I see something risky: AIUI, =E2=80=98zmq-message-content=E2=80=99 returns = a bytevector that aliases a message=E2=80=99s buffer. The problem is that the bytevecto= r may still be used from Scheme after the message is destroyed, and then bad things can happen. Also, regarding the message API, my goal back then (but I never got around to it) was to not expose the msg API as such, and instead to have =E2=80=98zmq-send=E2=80=99, =E2=80=98zmq-receive=E2=80=99 etc. transpa= rently create msg_t objects. That simplifies things for users and perhaps also for the implementation. HTH, Ludo=E2=80=99.