Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async await broken in 1.6-beta.16 (Windows x64) #9002

Closed
jakobrosenberg opened this issue Aug 10, 2017 · 6 comments
Closed

async await broken in 1.6-beta.16 (Windows x64) #9002

jakobrosenberg opened this issue Aug 10, 2017 · 6 comments
Assignees
Milestone

Comments

@jakobrosenberg
Copy link

On Windows 10 x64 the following code works in a new Meteor project v1.5.1, but not v1.6-beta.16.

const Cars = new Mongo.Collection("cars")

const fakeDelay = async function () {
  return new Promise((resolve, reject) => {
    setTimeout(() => { resolve('we waited long enough') }, 1000)
  })
}

Meteor.methods({
  async findcar() {
    await fakeDelay()    
    return Cars.findOne()
  }
})

In the 1.6-beta.16 the code above produces the following error Exception while invoking method 'findcar' Error: Can't wait without a fiber

@aadamsx
Copy link

aadamsx commented Aug 10, 2017

wait -- we have to add an 'await' to the front of the function call if calling an async function? I thought we could do the following to make the async call:

// module_a.js => Meteor server-side

let thing = {};

// regular, fibered, sync function
thing.getNewThing = userId => {
  return thing;
}

// regular, fibered, sync function
thing.getThing = userId => {
  return thing;
}

// => don't  hold things up, so make async
thing.getExistingOrNewThingAsync = async userId => {
  let things = null;
  if (await thing.expiredOrNotExistsThing(userId)) {
    // adding await to sync function
    things = await thing.getNewThing(userId); // => regular sync function
    return things;
  }
  else {
    // adding await to sync function
    things = await thing.getThing(userId); // => regular sync function
    return things;
  }
}

export  { thing };
// login handler => server-side
import { thing } from 'imports/server/stuff/module_a';

Accounts.onLogin(user => {
  const userId = user && user.user && user.user._id || '';
  // don't want to hold up the login process on account of this function
  thing.getExistingOrNewThingAsync(userId); // => no await here, but is called async
});

Please correct me here!

@klaussner
Copy link
Contributor

A bit more debugging information: the error is thrown in the Cars.findOne call if an expression has been awaited before in the method. After the await, Promise.Fiber.current is undefined. Full stack trace:

Exception while invoking method 'findcar' Error: Can't wait without a fiber
    at Function.wait ([...]/dev_bundle/server-lib/node_modules/fibers/future.js:159:9)
    at Future.wait ([...]/dev_bundle/server-lib/node_modules/fibers/future.js:448:10)
    at SynchronousCursor._nextObject (packages/mongo/mongo_driver.js:1018:47)
    at SynchronousCursor.forEach (packages/mongo/mongo_driver.js:1052:22)
    at SynchronousCursor.map (packages/mongo/mongo_driver.js:1062:10)
    at SynchronousCursor.fetch (packages/mongo/mongo_driver.js:1086:17)
    at Cursor.(anonymous function) [as fetch] (packages/mongo/mongo_driver.js:876:44)
    at MongoConnection.findOne (packages/mongo/mongo_driver.js:783:56)
    at Mongo.Collection.findOne (packages/mongo/collection.js:334:29)
    at Promise.asyncApply (server/main.js:25:17)

@aadamsx If you don't await the promise returned by getExistingOrNewThingAsync, you are just ignoring the value it's resolved with. But that's off-topic for this issue. 🙂

@aadamsx
Copy link

aadamsx commented Aug 10, 2017

@klaussner yep, in my case, in this situation, I don't care about the return value.

@benjamn
Copy link
Contributor

benjamn commented Aug 10, 2017

Can we get a reproduction of this? Happy to take a look.

@benjamn benjamn self-assigned this Aug 10, 2017
@benjamn benjamn added this to the Release 1.6 milestone Aug 10, 2017
@klaussner
Copy link
Contributor

@benjamn https://github.com/klaussner/meteor-issues/tree/9002 (with @jakobrosenberg's example)

benjamn added a commit to meteor/babel that referenced this issue Aug 10, 2017
It does not seem possible to ensure that code after an await expression
runs in a Fiber if we use native await expressions. However, Promise.await
still works just fine.

meteor/meteor#9002
benjamn pushed a commit that referenced this issue Aug 10, 2017
@benjamn
Copy link
Contributor

benjamn commented Aug 10, 2017

This should be fixed if you run meteor update --release 1.6-beta.18 in your app. Thanks for reporting the problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants