Unpromised problems in Meteor 1.7 upgrage

Just trying to upgrade our project from 1.6 to 1.7.0.3
local mongo fixing worked as described (making it a real 3.4 mongo to allow the 3.6 upgrade). AS some developers mentioned the update command should actually at least fail if db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ) is not 3.4, and better - just fix it.

Node is on version 8.11.3.

Starting the app in development mode, I got a first error with a findOne call that through the following error:

AssertionError [ERR_ASSERTION]: Cannot await without a Fiber
at awaitPromise (C:\Users\Ohad.EA\AppData\Local.meteor\packages\promise\0.11.1\npm\node_modules\meteor-promise\promise_server.js:75:12)
at Promise.await (C:\Users\Ohad.EA\AppData\Local.meteor\packages\promise\0.11.1\npm\node_modules\meteor-promise\promise_server.js:60:12)
at SynchronousCursor._nextObject (packages/mongo/mongo_driver.js:1083:12)
at SynchronousCursor.forEach (packages/mongo/mongo_driver.js:1097:22)
at SynchronousCursor.map (packages/mongo/mongo_driver.js:1107:10)
at SynchronousCursor.fetch (packages/mongo/mongo_driver.js:1131:17)
at Cursor.(anonymous function) [as fetch] (packages/mongo/mongo_driver.js:879:44)
at MongoConnection.findOne (packages/mongo/mongo_driver.js:786:56)
at Collection.findOne (packages/mongo/collection.js:356:29)
imports/api/users/server/monitorUsers.js:22:26 (that’s my code)

I solved that by wrapping the call in a Meteor.bindEnvironment(), although I shouldn’t - No reason that synchronous code on the server will stop running.

Next error is:
(node:15620) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
at Array.some ()
at Object.matchObject (packages/ejson/ejson.js:180:31)
at toJSONValueHelper (packages/ejson/ejson.js:239:19)
at Object.EJSON.toJSONValue.item [as toJSONValue] (packages/ejson/ejson.js:292:19)
at Object.keys.forEach.key (packages/ejson/ejson.js:188:29)
at Array.forEach ()
at Object.toJSONValue (packages/ejson/ejson.js:187:24)
at toJSONValueHelper (packages/ejson/ejson.js:240:24)
at Object.EJSON.toJSONValue.item [as toJSONValue] (packages/ejson/ejson.js:292:19)
at Object.keys.forEach.key (packages/ejson/ejson.js:188:29)
at Array.forEach ()
at Object.toJSONValue (packages/ejson/ejson.js:187:24)
at toJSONValueHelper (packages/ejson/ejson.js:240:24)
at Object.EJSON.toJSONValue.item [as toJSONValue] (packages/ejson/ejson.js:292:19)
at Object.keys.forEach.key (packages/ejson/ejson.js:188:29)
at Array.forEach ()

This error is originated from a inside collection.aggregate().map(…), when the aggregated cursor promised should deliver.
At this point I stop - something is wrong with the way promises are handled, and I need help to figure out what is wrong with at least one of the core packages.

All of this code worked well in version 1.6. So the errors have to do with one or more of the new components - mongo, NPM or babel?

I am seeing similar issues with code that worked absolutely fine before. @ohadb Were you able to find the culprit? TIA

I gave up the upgrade to v1.7 for now. Too many other priorities, and it is not yet critical to upgrade (e.g. security).
But I will revisit in a few months. Hopefully someone (maybe you?) will figure it out by then.
I suspect it is one or more packages that didn’t get updated to the correct version. I wish I knew which.

My current issues revolve around DataLoader, and that seems to have been an issue for others too it seems.

My issue seems to stem from the switch from the Babel config and a migration of @babel/preset-es2015 which is deprecated to @babel/preset-env, checking-out ahead and behind that point fixes/breaks the build for me.

That being said, apparently we should not be using it anyhow:

@ohadb

I ran into that as well. The reason is that in mongodb 3.6 aggregate always returns a cursor instead of an array with the results.

So collection.aggregate().map is not Array.map but AggregationCursor.map where the callback is called asynchrously. So therefore you need Meteor.bindEnvironment there (which you already added)

the second error is because the result of collection.aggregate().map() is still a cursor. You have to call await cursor.toArray() on it, if you need the result as a plain array. (toArray() returns a promise)

By the way: using flow-type helped me resolve that, because it can recognize if you have a promise or not and if you miss an await or so

@vincro

Which DataLoader do you mean and what are the build errors?

@macrozone

I was referring to the Cannot await without a Fiber errors which were happening during /graphql requests, not during the build.

My initial prognosis of the issue appeared to be with use of the npm dataloader package, but this was a proverbial red herring and the solution for me, was to resolve the babel presets.

Was the function async ? Usually that’s when this error gets triggered. (Look here: Error: Can't wait without a fiber)

And regarding the aggregate issue, yes, there was a change not in Meteor, but in official mongodb drivers that aggregate always returns an array.

We’ve had 0 issues when upgrading, on all of our active projects.