diff --git a/box.js b/box.js index 133bce7a6..3e34839f7 100755 --- a/box.js +++ b/box.js @@ -5,6 +5,7 @@ const constants = require('./src/constants.js'), fs = require('fs'), ldapServer = require('./src/ldapserver.js'), + net = require('net'), oidc = require('./src/oidc.js'), paths = require('./src/paths.js'), proxyAuth = require('./src/proxyauth.js'), @@ -25,6 +26,12 @@ async function setupLogging() { }; } +// happy eyeballs workaround. when there is no ipv6, nodejs timesout prematurely since the default for ipv4 is just 250ms +// https://github.com/nodejs/node/issues/54359 +async function setupNetworking() { + net.setDefaultAutoSelectFamilyAttemptTimeout(5000); +} + // this is also used as the 'uncaughtException' handler which can only have synchronous functions function exitSync(status) { const ts = new Date().toISOString(); @@ -37,6 +44,7 @@ function exitSync(status) { async function startServers() { await setupLogging(); + await setupNetworking(); await server.start(); // do this first since it also inits the database await proxyAuth.start(); await ldapServer.start(); diff --git a/src/taskworker.js b/src/taskworker.js index ee7c6f0fc..6f0820160 100755 --- a/src/taskworker.js +++ b/src/taskworker.js @@ -13,6 +13,7 @@ const apptask = require('./apptask.js'), externalLdap = require('./externalldap.js'), fs = require('fs'), mailServer = require('./mailserver.js'), + net = require('net'), reverseProxy = require('./reverseproxy.js'), safe = require('safetydance'), system = require('./system.js'), @@ -57,6 +58,11 @@ async function setupLogging() { process.stdout.logFile = logFile; // used by update task } +// happy eyeballs workaround. see box.js for detailed note +async function setupNetworking() { + net.setDefaultAutoSelectFamilyAttemptTimeout(5000); +} + // this is also used as the 'uncaughtException' handler which can only have synchronous functions function exitSync(status) { if (status.error) fs.write(logFd, status.error.stack + '\n', function () {}); @@ -70,6 +76,7 @@ const startTime = new Date(); async.series([ setupLogging, + setupNetworking, database.initialize, ], async function (initError) { if (initError) {