Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/compass-e2e-tests/tests/no-network-traffic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ describe('networkTraffic: false / Isolated Edition', function () {
const compass = await init(this.test?.fullTitle(), {
extraSpawnArgs: ['--no-network-traffic'],
wrapBinary,
// TODO(COMPASS-8166): firstRun: true seems to result in network traffic.
// Probably the welcome modal.
firstRun: false,
firstRun: true,
});
const browser = compass.browser;

Expand Down Expand Up @@ -117,7 +115,11 @@ describe('networkTraffic: false / Isolated Edition', function () {

if (
[...connectTargets].some(
(target) => !/^127.0.0.1:|^\[::1\]:/.test(target)
// Chromium heuristically detects IPv4-only networks by attempting a UDP connection
// to 2001:4860:4860::8888 (the IPv6 address for Google Public DNS).
(target) =>
!/^127.0.0.1:|^\[::1\]:/.test(target) &&
!/^\[2001:4860:4860::8888\]:443$/.test(target)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I guess this is something we can't control at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found one yet.
It seems like electron command line switches redirect it with the host rules / host resolver rules.
https://www.electronjs.org/docs/latest/api/command-line-switches#--host-rulesrules
I'll spend a bit of time looking into that and circle back before merging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early on in our application code to override the host resolution it looks like we can:

app.commandLine.appendSwitch('host-resolver-rules', 'MAP 2001:4860:4860::8888 some_address');

That will cause all of the network requests to start failing if it doesn't succeed though as I think more of the stack relies on this request for knowing where to send requests. I'm thinking as a fix we could maybe provide users a way to specify this themselves.

I'm going to merge this pr for the other fix and create a follow up ticket and link a todo in the code. I think it still needs a bit of investigation and thought

)
) {
throw new Error(`Connected to unexpected host! ${[...connectTargets]}`);
Expand Down
14 changes: 14 additions & 0 deletions packages/compass/src/main/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ class CompassApplication {
// Accessing isEncryptionAvailable is not allowed when app is not ready on Windows
// https://github.com/electron/electron/issues/33640
await app.whenReady();

const { networkTraffic } = this.preferences.getPreferences();

if (!networkTraffic) {
// Electron fetches spellcheck dictionaries from a CDN
// on all OSs expect mac (it provides a built-in spell check).
// Passing a non-resolving URL prevents it from fetching
// as there aren't any options to disable it provided.
// https://github.com/electron/electron/issues/22995
session.defaultSession.setSpellCheckerDictionaryDownloadURL(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow. well caught.

'http://127.0.0.1:0/'
);
}

log.info(
mongoLogId(1_001_000_307),
'Application',
Expand Down
9 changes: 0 additions & 9 deletions packages/compass/src/main/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,13 @@ function showConnectWindow(
};

debug('creating new main window:', windowOpts);
const { preferences } = compassApp;
const { networkTraffic } = preferences.getPreferences();

let window: BrowserWindow | null = new BrowserWindow(windowOpts);
if (mongodbUrl) {
registerMongoDbUrlForBrowserWindow(window, mongodbUrl);
}
if (connectionId) {
registerConnectionIdForBrowserWindow(window, connectionId);
}
if (networkTraffic !== true) {
// https://github.com/electron/electron/issues/22995
window.webContents.session.setSpellCheckerDictionaryDownloadURL(
'http://127.0.0.1:0/'
);
}

enable(window.webContents);
const unsubscribeProxyListenerPromise = compassApp.setupProxySupport(
Expand Down
Loading