From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.bugs Subject: bug#16775: dbus interacts poorly with lisp-level event loops Date: Mon, 17 Feb 2014 03:17:04 -0800 Message-ID: <5301EFB0.7000400@dancol.org> References: <5301EAE0.5080008@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1392635889 27545 80.91.229.3 (17 Feb 2014 11:18:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 17 Feb 2014 11:18:09 +0000 (UTC) To: 16775@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 17 12:18:17 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WFMDH-0007x9-UZ for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Feb 2014 12:18:16 +0100 Original-Received: from localhost ([::1]:39157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFMDH-0006O6-Cc for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Feb 2014 06:18:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFMD9-0006Nb-6x for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:18:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFMD4-0005as-Ba for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:18:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54664) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFMD4-0005an-86 for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WFMD4-0006Xj-2c for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Colascione Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Feb 2014 11:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 16775 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.139263585225108 (code B ref -1); Mon, 17 Feb 2014 11:18:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Feb 2014 11:17:32 +0000 Original-Received: from localhost ([127.0.0.1]:55846 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WFMCa-0006Wu-3n for submit@debbugs.gnu.org; Mon, 17 Feb 2014 06:17:32 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:50178) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WFMCW-0006We-PQ for submit@debbugs.gnu.org; Mon, 17 Feb 2014 06:17:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFMCM-0005NW-Cy for submit@debbugs.gnu.org; Mon, 17 Feb 2014 06:17:23 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:49475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFMCM-0005NO-9M for submit@debbugs.gnu.org; Mon, 17 Feb 2014 06:17:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFMCH-0006Lb-5x for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:17:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFMCB-0005Ln-DL for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:17:13 -0500 Original-Received: from dancol.org ([2600:3c01::f03c:91ff:fedf:adf3]:60072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFMCA-0005LV-UD for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 06:17:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dancol.org; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Subject:To:MIME-Version:From:Date:Message-ID; bh=HcMKHL/HuBZrDfFxy8T7pqhX9cAseeHNR9eiATno0CE=; b=auwyY6FA1D0dAthmHpO0oOuNjaBvmhULv0bumPbJgKifjQEeRv4mc2hw044jcL9UbNIyxRKqFxZPP9pDRWxmR9Rsx2qJskpAoRDtUkv0/4uNLqYMIkkiC6oBq41JhbTv2ogdk984osJp50+AgEZxIc2MrM400eo7SDFKmbePb0tP0IUUoSiCVyQK71WGH2B6wIz5KV+IQI76LmbBdZ8oPRqhPde6pMDm90rhVpwrDvuhPKMkxQDejnmM9cnAbq79VC3wCyKgp8pfLdtiGkMEYj7fTBRGOXSQ9UpUOnPGEnUlj9FN4FKeLRWLiMjmACv1xg+n93h4oQ+GXK5QBu7BaQ==; Original-Received: from c-76-104-210-106.hsd1.wa.comcast.net ([76.104.210.106] helo=[192.168.1.50]) by dancol.org with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1WFMC9-0007kZ-Se for bug-gnu-emacs@gnu.org; Mon, 17 Feb 2014 03:17:05 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <5301EAE0.5080008@dancol.org> X-Forwarded-Message-Id: <5301EAE0.5080008@dancol.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:85719 Archived-At: -------- Original Message -------- Subject: Re: dbus-call-method takes a minimum of 100ms per call?! Date: Mon, 17 Feb 2014 02:56:32 -0800 From: Daniel Colascione To: Emacs developers On 02/16/2014 09:15 PM, Daniel Colascione wrote: > I think we're supposed to exit as soon as we get a dbus event and > short-circuit the timeout, but no such event seems to get delivered, > even for successful calls. I can dig a bit into dbusbind.c, but I'm no > dbus expert. dbus-call-method expects read-event to return the dbus event immediately, but read_char in keyboard.c treats the dbus event as a special event and runs it through special-event-map itself before sitting and reading another event. The event waiting loop always times out, so dbus-call-method always takes at least 100ms due to the hard-coded 0.1 timeout parameter to read-event. This problem is hairy: special-event-map functions can execute arbitrary code and re-enter the dbus synchronous event loop, and there's no way to non-locally terminate a particular read-event loop. Here's the problematic scenario: dbus-call-method works by setting up an asynchronous dbus call and calling read-event until the specific asynchronous call on which it is waiting completes. The immediate problem is that read-event never actually returns because the dbus event is special --- but let's say we worked around that problem by modifying special-event-map around the read-event call so that read-event returned immediately. We'd still have a serious issue because *other*, non-dbus special event handles can run arbitrary code and enter an inner dbus-call-method reply-waiting loop. If the reply to the outer synchronous dbus call arrives before the reply to the inner synchronous dbus call, dbus-call-method-handler (which is run from special-event-map inside read-event or, in our hypothetical partial fix, manually from the wait loop) will dutifully put the reply on dbus-return-values-table. But the inner event loop has no way of waking the *outer* event loop, so when the special event handler that called the inner dbus-call-method returns, read_char will loop around and wait for the full timeout period before returning to the outer dbus-call-method. If dbus had been implemented as a process type instead of a special event source, we'd just be able to use accept-process-output in dbus-call.