Skip to content

Commit 00833db

Browse files
committed
Fix avahi blocking forever on Windows
Fixes e7ac871
1 parent 2265a43 commit 00833db

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/dnssd/avahi.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ let cachedServer: Server | undefined;
5353
async function getServer(): Promise<Server> {
5454
if (cachedServer === undefined) {
5555
const bus = dbus.systemBus();
56+
// dbus-next will queue messages and wait forever for a connection
57+
// so we have to hack in a timeout, otherwise we end up with a deadlock
58+
// on systems without D-Bus.
59+
await new Promise((resolve, reject) => setTimeout(() => {
60+
if ((bus as any)._connection.state === 'connected') {
61+
resolve();
62+
} else {
63+
reject(Error("Timeout while connecting to D-Bus"));
64+
}
65+
}, 100));
5666
const proxy = await bus.getProxyObject('org.freedesktop.Avahi', '/');
5767
const server = proxy.getInterface<Server>('org.freedesktop.Avahi.Server');
5868
const version = await server.GetAPIVersion();

0 commit comments

Comments
 (0)