From 92233e132cb98ae969a38f9ab1b7d4d94f0486b9 Mon Sep 17 00:00:00 2001 From: Edimar Cardoso Date: Tue, 6 Dec 2022 20:35:57 -0300 Subject: [PATCH 1/3] Require review alternative to Fibers uses --- .../common/livedata_connection.js | 3 +- .../test/livedata_test_service.js | 6 ++-- .../ddp-client/common/livedata_connection.js | 3 +- packages/ddp-client/package.js | 5 --- packages/ddp-server/writefence.js | 3 +- .../stylus/plugin/compile-stylus.js | 3 +- packages/meteor/async_helpers.js | 2 -- packages/meteor/helpers.js | 4 ++- tools/isobuild/bundler.js | 1 - tools/static-assets/server/boot.js | 31 ++++++++++--------- 10 files changed, 31 insertions(+), 30 deletions(-) diff --git a/packages/ddp-client-async/common/livedata_connection.js b/packages/ddp-client-async/common/livedata_connection.js index c30ff6f48d..1ea402ec98 100644 --- a/packages/ddp-client-async/common/livedata_connection.js +++ b/packages/ddp-client-async/common/livedata_connection.js @@ -19,7 +19,8 @@ let Fiber; let Future; if (Meteor.isServer) { Fiber = Npm.require('fibers'); - Future = Npm.require('fibers/future'); + // TODO Review fiber use + Future = Meteor._isFibersEnabled ? Npm.require('fibers/future') : null; } class MongoIDMap extends IdMap { diff --git a/packages/ddp-client-async/test/livedata_test_service.js b/packages/ddp-client-async/test/livedata_test_service.js index db32cf3cc4..11326e99c3 100644 --- a/packages/ddp-client-async/test/livedata_test_service.js +++ b/packages/ddp-client-async/test/livedata_test_service.js @@ -34,7 +34,8 @@ Meteor.methods({ // We used to improperly serialize errors that were thrown through a // future first. - if (Meteor.isServer && options.throwThroughFuture) { + // TODO Review fiber use + if (Meteor.isServer && options.throwThroughFuture && Meteor._isFibersEnabled) { const Future = Npm.require('fibers/future'); const f = new Future(); f['throw'](e); @@ -59,7 +60,8 @@ if (Meteor.isServer) { // other. const waiters = Object.create(null); - const Future = Npm.require('fibers/future'); + // TODO Review fiber use + const Future = Meteor._isFibersEnabled ? Npm.require('fibers/future') : null; const returnThroughFuture = function(token, returnValue) { // Make sure that when we call return, the fields are already cleared. diff --git a/packages/ddp-client/common/livedata_connection.js b/packages/ddp-client/common/livedata_connection.js index c30ff6f48d..da7bd848c4 100644 --- a/packages/ddp-client/common/livedata_connection.js +++ b/packages/ddp-client/common/livedata_connection.js @@ -17,7 +17,8 @@ import { let Fiber; let Future; -if (Meteor.isServer) { +// TODO Review fiber use +if (Meteor.isServer && Meteor._isFibersEnabled) { Fiber = Npm.require('fibers'); Future = Npm.require('fibers/future'); } diff --git a/packages/ddp-client/package.js b/packages/ddp-client/package.js index 64cbf8d09e..0cdc77a953 100644 --- a/packages/ddp-client/package.js +++ b/packages/ddp-client/package.js @@ -9,11 +9,6 @@ Npm.depends({ }); Package.onUse((api) => { - if (process.env.DISABLE_FIBERS) { - api.use('ddp-client-async'); - api.export('DDP', 'server'); - return; - } api.use([ 'check', 'random', diff --git a/packages/ddp-server/writefence.js b/packages/ddp-server/writefence.js index e9310c9f7f..d480f89500 100644 --- a/packages/ddp-server/writefence.js +++ b/packages/ddp-server/writefence.js @@ -1,4 +1,5 @@ -var Future = Npm.require('fibers/future'); +// TODO Review fiber use +var Future = Meteor._isFibersEnabled ? Npm.require('fibers/future') : null; // A write fence collects a group of writes, and provides a callback // when all of the writes are fully committed and propagated (all diff --git a/packages/deprecated/stylus/plugin/compile-stylus.js b/packages/deprecated/stylus/plugin/compile-stylus.js index cc0003d3e3..5d6e5b492d 100644 --- a/packages/deprecated/stylus/plugin/compile-stylus.js +++ b/packages/deprecated/stylus/plugin/compile-stylus.js @@ -1,7 +1,8 @@ const stylus = Npm.require('stylus'); const nib = Npm.require('nib'); const autoprefixer = Npm.require('autoprefixer-stylus'); -const Future = Npm.require('fibers/future'); +// TODO Review fiber use +const Future = Meteor._isFibersEnabled ? Npm.require('fibers/future') : null; const fs = Plugin.fs; const path = Plugin.path; diff --git a/packages/meteor/async_helpers.js b/packages/meteor/async_helpers.js index e326265c03..e8862322f3 100644 --- a/packages/meteor/async_helpers.js +++ b/packages/meteor/async_helpers.js @@ -1,5 +1,3 @@ -var Fiber = Npm.require('fibers'); -var Future = Npm.require('fibers/future'); Meteor._noYieldsAllowed = function (f) { return f(); diff --git a/packages/meteor/helpers.js b/packages/meteor/helpers.js index 242921945c..2cdac99646 100644 --- a/packages/meteor/helpers.js +++ b/packages/meteor/helpers.js @@ -1,4 +1,6 @@ -if (Meteor.isServer) + +// TODO Review fiber use +if (Meteor.isServer && Meteor._isFibersEnabled) var Future = Npm.require('fibers/future'); if (typeof __meteor_runtime_config__ === 'object' && diff --git a/tools/isobuild/bundler.js b/tools/isobuild/bundler.js index 05157fea70..c354eac1d4 100644 --- a/tools/isobuild/bundler.js +++ b/tools/isobuild/bundler.js @@ -149,7 +149,6 @@ // wait until later. var assert = require('assert'); -var Fiber = require('fibers'); var _ = require('underscore'); var compiler = require('./compiler.js'); diff --git a/tools/static-assets/server/boot.js b/tools/static-assets/server/boot.js index 68ae408045..c70dcaaa0b 100644 --- a/tools/static-assets/server/boot.js +++ b/tools/static-assets/server/boot.js @@ -1,7 +1,7 @@ -var Fiber = require("fibers"); +// var Fiber = require("fibers"); var fs = require("fs"); var path = require("path"); -var Future = require("fibers/future"); +//var Future = require("fibers/future"); var sourcemap_support = require('source-map-support'); var bootUtils = require('./boot-utils.js'); @@ -52,8 +52,9 @@ if (!process.env.APP_ID) { // Map from load path to its source map. var parsedSourceMaps = {}; +// TODO Review fiber use const meteorDebugFuture = - process.env.METEOR_INSPECT_BRK ? new Future : null; + process.env.METEOR_INSPECT_BRK ? null : null; function maybeWaitForDebuggerToAttach() { if (meteorDebugFuture) { @@ -75,7 +76,7 @@ function maybeWaitForDebuggerToAttach() { `Debugger did not attach after ${waitLimitMinutes} minutes; continuing.` ); - meteorDebugFuture.return(); + //meteorDebugFuture.return(); } else { // This pause function contains a debugger keyword that will only @@ -95,7 +96,7 @@ function maybeWaitForDebuggerToAttach() { // time, we can conclude the debugger keyword must be active, // which means a debugging client must be connected, which means // we should stop polling and let the main Fiber continue. - meteorDebugFuture.return(); + //meteorDebugFuture.return(); } else { // If the pause() function call didn't take a meaningful amount @@ -108,7 +109,7 @@ function maybeWaitForDebuggerToAttach() { }, pollIntervalMs); // The polling will continue while we wait here. - meteorDebugFuture.wait(); + //meteorDebugFuture.wait(); } } @@ -311,8 +312,8 @@ var loadServerBundles = Profile("Load server bundles", function () { var getAsset = function (assetPath, encoding, callback) { var fut; if (! callback) { - fut = new Future(); - callback = fut.resolver(); + //fut = new Future(); + //callback = fut.resolver(); } // This assumes that we've already loaded the meteor package, so meteor // itself can't call Assets.get*. (We could change this function so that @@ -499,12 +500,12 @@ function startServerProcess() { }); } -if (IS_FIBERS_ENABLED) { - Fiber(function() { - startServerProcess(); - }).run(); - return; -} else { +// if (IS_FIBERS_ENABLED) { +// Fiber(function() { +// startServerProcess(); +// }).run(); +// return; +// } else { startServerProcess(); -} +//} From 283b5acc2e2e151c3987805d9e56a0b3e8677001 Mon Sep 17 00:00:00 2001 From: Edimar Cardoso Date: Wed, 7 Dec 2022 09:49:29 -0300 Subject: [PATCH 2/3] Login commands test --- tools/meteor-services/auth.js | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/meteor-services/auth.js b/tools/meteor-services/auth.js index 67fbf7333a..c90ccdc5a4 100644 --- a/tools/meteor-services/auth.js +++ b/tools/meteor-services/auth.js @@ -10,16 +10,16 @@ var Console = require('../console/console.js').Console; var auth = exports; -function loadDDP() { - return require("../tool-env/isopackets.js") - .loadIsopackage("ddp-client") - .DDP; +async function loadDDP() { + const isopackage = require("../tool-env/isopackets.js"); + const { DDP } = await isopackage.loadIsopackage("ddp-client"); + return DDP; } // Opens and returns a DDP connection to the accounts server. Remember // to close it when you're done with it! -var openAccountsConnection = function () { - return loadDDP().connect(config.getAuthDDPUrl(), { +var openAccountsConnection = async function () { + return (await loadDDP()).connect(config.getAuthDDPUrl(), { headers: { 'User-Agent': httpHelpers.getUserAgent() } }); }; @@ -28,9 +28,9 @@ var openAccountsConnection = function () { // that is a connection to the accounts server, which gets closed when // `f` returns or throws. var withAccountsConnection = function (f) { - return function (...args) { + return async function (...args) { var self = this; - var conn = openAccountsConnection(); + var conn = await openAccountsConnection(); args.push(conn); try { var result = f.apply(self, args); @@ -47,7 +47,7 @@ var withAccountsConnection = function (f) { // XXX if we reconnect we won't reauthenticate. Fix that before using // this for long-lived connections. var loggedInAccountsConnection = async function (token) { - var connection = loadDDP().connect( + var connection = (await loadDDP()).connect( config.getAuthDDPUrl() ); @@ -91,13 +91,13 @@ var loggedInAccountsConnection = async function (token) { // provided, one will be opened and then closed before returning. var sessionMethodCaller = function (methodName, options) { options = options || {}; - return function (...args) { + return async function (...args) { args.push({ session: auth.getSessionId(config.getAccountsDomain()) || null }); var timer; - var conn = options.connection || openAccountsConnection(); + var conn = options.connection || await openAccountsConnection(); function cleanUp() { timer && clearTimeout(timer); @@ -289,7 +289,7 @@ var removePendingRevoke = function (domain, tokenIds) { // session. just changes the error message. // - connection: an open connection to the accounts server. If not // provided, this function will open one itself. -var tryRevokeOldTokens = function (options) { +var tryRevokeOldTokens = async function (options) { options = Object.assign({ timeout: 5000 }, options || {}); @@ -313,8 +313,7 @@ var tryRevokeOldTokens = function (options) { warned = true; } }; - - _.each(domainsWithRevokedTokens, function (domain) { + for (const domain in domainsWithRevokedTokens) { var data = readSessionData(); var session = data.sessions[domain] || {}; var tokenIds = session.pendingRevoke || []; @@ -327,7 +326,7 @@ var tryRevokeOldTokens = function (options) { if (session.type === "meteor-account") { try { - sessionMethodCaller('revoke', { + await sessionMethodCaller('revoke', { timeout: options.timeout, connection: options.connection })(tokenIds); @@ -346,7 +345,7 @@ var tryRevokeOldTokens = function (options) { logoutFailWarning(domain); return; } - }); + } }; var sendAuthorizeRequest = function (clientId, redirectUri, state) { @@ -457,7 +456,7 @@ var oauthFlow = function (conn, options) { // error message to stderr if the login fails // - connection: an open connection to the accounts server. If not // provided, this function will open its own connection. -var doInteractivePasswordLogin = function (options) { +var doInteractivePasswordLogin = async function (options) { var loginData = {}; if (_.has(options, 'username')) { @@ -478,7 +477,7 @@ var doInteractivePasswordLogin = function (options) { } }; - var conn = options.connection || openAccountsConnection(); + var conn = options.connection || await openAccountsConnection(); var maybeCloseConnection = function () { if (! options.connection) { @@ -576,7 +575,7 @@ exports.loginCommand = withAccountsConnection(async function (options, loginOptions.connection = connection; - if (! doInteractivePasswordLogin(loginOptions)) { + if (! await doInteractivePasswordLogin(loginOptions)) { return 1; } } From 1df9607b6107909097b2b77830d14198b4739424 Mon Sep 17 00:00:00 2001 From: Edimar Cardoso Date: Wed, 7 Dec 2022 09:49:52 -0300 Subject: [PATCH 3/3] Login commands test --- tools/cli/commands.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 71a49e5f8e..a853d175ef 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -2170,8 +2170,8 @@ main.registerCommand({ email: { type: Boolean } }, catalogRefresh: new catalog.Refresh.Never() -}, function (options) { - return auth.loginCommand(Object.assign({ +}, async function (options) { + return await auth.loginCommand(Object.assign({ overwriteExistingToken: true }, options)); });