From 3943d72a81ec59abc89ec5abf04b4e0ae0db89d3 Mon Sep 17 00:00:00 2001 From: Ali Polatel Date: Tue, 24 Apr 2012 02:46:27 +0300 Subject: [PATCH] Re: [PATCH] ruby: make sure the database is closed --- e5/3a04533945abdee4b5fb0d65c2859d59f80070 | 176 ++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 e5/3a04533945abdee4b5fb0d65c2859d59f80070 diff --git a/e5/3a04533945abdee4b5fb0d65c2859d59f80070 b/e5/3a04533945abdee4b5fb0d65c2859d59f80070 new file mode 100644 index 000000000..5403843a6 --- /dev/null +++ b/e5/3a04533945abdee4b5fb0d65c2859d59f80070 @@ -0,0 +1,176 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0179C431FAF + for ; Mon, 23 Apr 2012 16:46:50 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.699 +X-Spam-Level: +X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 9Kxx090A319m for ; + Mon, 23 Apr 2012 16:46:49 -0700 (PDT) +Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com + [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7AC0C431FAE + for ; Mon, 23 Apr 2012 16:46:49 -0700 (PDT) +Received: by bkcjm2 with SMTP id jm2so180939bkc.26 + for ; Mon, 23 Apr 2012 16:46:47 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=mime-version:sender:in-reply-to:references:from:date + :x-google-sender-auth:message-id:subject:to:cc:content-type + :content-transfer-encoding; + bh=7xYckBiySqEncjt2n3rvMxKil5xmjoocg38cZLfrowg=; + b=HoRtfkTMJMCwV5OpbQjGg0DhKjihWus3xelGiG4z06RgXC4uCsGHtevqFaShD+hPf7 + U3KR5iQ7MAgsmrpuIH3SZveXb7F8v3MBbU95EzmGgZei3+AHkU5BgUi1bBZXyuu+yoGe + PPasLtH1KNUJi+e6/Nz19EryPFml3hkMhxXMGSNutdUL0qLw/olG6EKnJFVqL7xpOyOX + u66gi1YJVjX8V2R05/7hayxbCOQAKwqjc707bJmOGfL81cm9KLDsbj4spoz9hOip108m + Y8IS2zROfkXNdONf7qnI6Q7c0y1LMK8khP45lPmU/YYw2dIHfyz8jf2PN7gLzM4kDsZe + jHfA== +Received: by 10.204.152.14 with SMTP id e14mr5601257bkw.29.1335224807769; Mon, + 23 Apr 2012 16:46:47 -0700 (PDT) +MIME-Version: 1.0 +Sender: polatel@gmail.com +Received: by 10.204.123.73 with HTTP; Mon, 23 Apr 2012 16:46:27 -0700 (PDT) +In-Reply-To: + +References: <1335185032-13075-1-git-send-email-felipe.contreras@gmail.com> + + + + +From: Ali Polatel +Date: Tue, 24 Apr 2012 02:46:27 +0300 +X-Google-Sender-Auth: Zf6lpMdc_sHRazsUQlgEXB3TYas +Message-ID: + +Subject: Re: [PATCH] ruby: make sure the database is closed +To: Felipe Contreras +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 23 Apr 2012 23:46:51 -0000 + +2012/4/24 Felipe Contreras : +> On Mon, Apr 23, 2012 at 11:43 PM, Ali Polatel wrote: +>> 2012/4/23 Felipe Contreras : +>>> On Mon, Apr 23, 2012 at 5:04 PM, Ali Polatel wrote: +>>> +>>>> I'd rather not do this. +>>>> Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/32= +0324 +>>> +>>> OK, I've read this.. So? +>> +>> You are one step close to what I thought you had thought. +> +> I don't parse that. I meant that _now_ I've read it. + +Sorry, my subconscious likes to barf on emails every now and then. + +>>> The order in which Ruby's garbage-collector frees the database and +>>> other objects is irrelevant, because with this patch we are not +>>> manually freeing other objects, only the database. +>> +>> What I wanted was to make all objects "depending" on the database to be = +unusable +>> once the database object is freed. Seeing that's not practically easy +>> I decided to leave +>> it to the user. +> +> Well, sure, but if the user has problems, the user can keep the +> database object around. +> +> Personally I don't see why an object, like say a query would remain +> working correctly after the database is gone, either by calling +> .close() directly, or just loosing the pointer to the original object. +> I don't think users would expect that, or, even if they somehow found +> it useful, that most likely would be very seldom, and hardly worth +> worrying about it. + +Working correctly is not expected but wouldn't it be more appropriate +to throw an exception rather than dumping core or printing on standard erro= +r? + +>>> Sure, it's _better_ if the user calls close(), even better if it's +>>> inside an 'ensure', and even better if blocks are used (which I am +>>> using in most cases), but that's not *required*. +>> +>> If you have such a use case, I'm fine with that patch. +>> I might push it in the next few days or get someone else to push it. +> +> I did at some point, not sure if I do now. But that's beside the +> point, the point is that it really does happen. +> +>>> The user might just do: +>>> +>>> def foo +>>> =A0db =3D Notmuch::Database.new($db_name, :mode =3D> Notmuch::MODE_READ= +_WRITE) +>>> end +>>> +>>> That's perfectly fine in Ruby (although not ideal), since 'db' will +>>> get garbage-collected. But nobody will be able to use the database +>>> again until that process is killed. +>>> +>>> You think that's correct? +>> +>> Yes that is correct. I have not thought about this. +>> I'd say it's a partial misunderstanding on my part due to lack of +>> (and/or too much) vodka. +> +> Well, there's only two options. +> +> a) This works: +> +> =A0def foo +> =A0 =A0db =3D Notmuch::Database.new($db_name, :mode =3D> Notmuch::MODE_RE= +AD_WRITE) +> =A0end +> +> (as in; the database gets closed eventually) +> +> b) This works: +> +> =A0def start_query(search) +> =A0 =A0db =3D Notmuch::Database.new($db_name) +> =A0 =A0return db.query(search) +> =A0end +> +> (as in; the query returned would keep working properly) +> +> I personally don't see why anybody would want b), and if they have +> problems with code like that, I think it's obvious to see why. +> +> I think we should go for a) and thus apply the patch. + +I wonder whether we can make both work somehow. +Maybe by using talloc explicitly and keeping reference pointers? +I don't know whether it's worth bothering. + +> Cheers. + +Cheers + +> -- +> Felipe Contreras + + -alip -- 2.26.2