-
Notifications
You must be signed in to change notification settings - Fork 416
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
Strange behavior with Mongoose #70
Comments
This is more likely to do with connection pooling than with this package. Check Mongoose's docs for how to drain/close the pool, there usually is a way. Does it work without Webpack in production? |
Had a very similar issue that drove me insane, was fixed it for me was to close the Mongo db connection. |
Note |
I would use the native Promise on 6.10 as there are other threads with a similar issue. |
Any solution for this? |
If you set That might lead to races in AWS' Lambda code (does the callback get fired first, or does the returned promise resolve first?). AWS Lambda supports returning promises from handlers instead of using the callbacks since a while. A safe and correct implementation would be:
It might be that using the plugin or using webpack externally creates slightly different code with different timing behavior. |
@mrpatiwi Is this issue still valid? In the meantime |
Closing the issue as there has been no feedback. Feel free to reopen it or create a new one for the most current version if the issue still persists. |
@HyperBrain I'm also having this issue. Has anyone found any solution ?
import 'babel-polyfill';
import { createInsertDocHandler } from './handlers';
import createRepository from './repositories/mongodb';
const db = createRepository(process.env.DB_URL);
exports.insertDoc = createInsertDocHandler(db);
import debug from 'debug';
import dummyModel from '../util/models/dummy';
import responseWrapper from '../util/responseWrapper';
const mapBodyResponse = ({ _id, name }) => ({ _id, name });
export const createInsertDocHandler = db => async (event, context, callback) => {
debug('function:req:params')(event.pathParameters);
debug('function:req:body')(JSON.parse(event.body));
context.callbackWaitsForEmptyEventLoop = false;
const document = await db
.insert(dummyModel, query)
.then(doc => doc)
.catch(e => callback);
debug('function:res')(document);
return callback(null, document);
}
import mongoose from 'mongoose';
const createRepository = url => {
mongoose.connect(url).connect;
return {
insert: async (model, query) => model.create(query),
};
};
export default createRepository; I have debugged the deployed version of this function and the insertion operation is being carried away however I'm receiving a 500 whilst performing with rerverless-offline I get this warning |
Trying mongoose with
context.callbackWaitsForEmptyEventLoop = false
so the function should end after callingcallback(...)
works different while usingserverless-webpack
as a plugin and when manually packing the project with webpack.With
serverless-webpack
When calling the function it gets stuck on some event-loop and eventually it times-out on AWS.
Without
serverless-webpack
Manually running
webpack
and:And then running it locally or on production it work as expected.
The text was updated successfully, but these errors were encountered: