dbus-daemon on Windows: Failed to bind socket "localhost:59367": Address already in use
Thomas Sondergaard <ts-2vlBz+Gd9o2sRyR5/[email protected]>
| Newsgroups | gmane.comp.freedesktop.dbus |
|---|---|
| Message-ID | <[email protected]> |
When I run the attached test programs I get a handful or so of cases where the dbus-daemon fails to start with a message like Failed to bind socket "localhost:59367": Address already in use This surprises me. First I thought it was some kind of race condition when starting multiple buses at the same time (dbus-test.cc), but it also fails a handful of times out of a thousand when only one process is started at a time (dbus-test-nothreads.cc). This is using D-Bus Message Bus Daemon 1.8.10 on Windows. Steps to reproduce: 1. Compile the small test program on Windows 2. Make sure dbus-daemon is in the path 3. Run the test program The nothreads version takes about 4 minutes to run. Regards, Thomas _______________________________________________ dbus mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dbus
dbus-test.cc
(text/x-c++src, 1.3 KB)
#include <iostream>
#include <vector>
#include <QCoreApplication>
#include <QEventLoop>
#include <QProcess>
#include <QtConcurrentRun>
#include <QTimer>
using namespace std;
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
typedef std::vector<QFuture<void>> VoidFutureVector;
VoidFutureVector futures;
QThreadPool::globalInstance()->setMaxThreadCount(200);
int i;
for (i = 0; i < 1000; ++i) {
futures.emplace_back(QtConcurrent::run([i] {
//cerr << "Starting DBusDaemonProcess " << i << endl;
QProcess process;
process.setProcessChannelMode(QProcess::ForwardedChannels);
process.start("dbus-daemon",
QStringList()<< "--session" << "--print-address" << "--address=tcp:host=localhost,port=0");
QTimer timer;
QEventLoop eventloop;
QObject::connect(&timer, SIGNAL(timeout()), &eventloop, SLOT(quit()));
timer.setSingleShot(true);
timer.start(1000);
eventloop.exec();
process.kill();
process.waitForFinished();
//cerr << "Stopping DBusDaemonProcess " << i << endl;
}));
}
for (QFuture<void> &future : futures)
future.waitForFinished();
cerr << "Program done" << endl;
}
dbus-test-nothreads.cc
(text/x-c++src, 804 B)
#include <iostream>
#include <vector>
#include <QCoreApplication>
#include <QEventLoop>
#include <QProcess>
#include <QTimer>
using namespace std;
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
for (int i = 0; i < 1000; ++i) {
QProcess process;
process.setProcessChannelMode(QProcess::ForwardedChannels);
process.start("dbus-daemon",
QStringList() << "--session" << "--address=tcp:host=localhost,port=0");
QTimer timer;
QEventLoop eventloop;
QObject::connect(&timer, SIGNAL(timeout()), &eventloop, SLOT(quit()));
timer.setSingleShot(true);
timer.start(250);
eventloop.exec();
process.kill();
process.waitForFinished();
}
cerr << "Program done" << endl;
}