local sync: fix timeout with local sync with libdbus

When using libdbus instead of GIO D-Bus (as done by syncevolution.org
binaries and SyncEvolution on Maemo), local sync may have aborted
after 25 seconds when syncing many items with a D-Bus timeout error:

[ERROR] sending message to child failed: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

Reported by Toke Høiland-Jørgensen for Harmattan. Somehow not encountered
elsewhere.

Root cause is the use of the default D-Bus timeout of 25 seconds
instead of disabling the timeout altogether. Fixed by using
DBUS_TIMEOUT_INFINITE and INT_MAX as fallback.
This commit is contained in:
Patrick Ohly 2012-08-23 13:57:29 +02:00
parent 92b3196bc6
commit 406f5a0d40

View file

@ -60,6 +60,14 @@
#include "gdbus.h"
#include "gdbus-cxx.h"
// Not defined by 1.4.x in Maemo Harmattan; INT_MAX has the same
// value and effect there. In older libdbus, it is the same as
// a very long timeout (2147483s), which is good enough.
#include <stdint.h>
#ifndef DBUS_TIMEOUT_INFINITE
# define DBUS_TIMEOUT_INFINITE INT_MAX
#endif
#include <map>
#include <vector>
#include <utility>
@ -4213,7 +4221,7 @@ protected:
void send(DBusMessagePtr &msg, const Callback_t &callback)
{
DBusPendingCall *call;
if (!dbus_connection_send_with_reply(m_conn.get(), msg.get(), &call, -1)) {
if (!dbus_connection_send_with_reply(m_conn.get(), msg.get(), &call, DBUS_TIMEOUT_INFINITE)) {
throw std::runtime_error("dbus_connection_send failed");
} else if (call == NULL) {
throw std::runtime_error("received pending call is NULL");
@ -4233,7 +4241,7 @@ protected:
DBusErrorCXX error;
// Constructor steals reference, reset() doesn't!
// Therefore use constructor+copy instead of reset().
DBusMessagePtr reply = DBusMessagePtr(dbus_connection_send_with_reply_and_block(m_conn.get(), msg.get(), -1, &error));
DBusMessagePtr reply = DBusMessagePtr(dbus_connection_send_with_reply_and_block(m_conn.get(), msg.get(), DBUS_TIMEOUT_INFINITE, &error));
if (!reply) {
error.throwFailure(m_method);
}