Closed DesignByOnyx closed 7 years ago
@DesignByOnyx Let me try to reproduce this first can you also tell me your used node version?
Coming back to you in a few minutes.
Hey, I just switched to a new machine 2 days ago and thought this was on node 6 but it's actually on v5.6.0. But I can confirm the issue is happening on Travis running on v6.5.0.
Also, I think the problem has to do with the fact that callback is always ever defined on the internals object: https://github.com/DesignByOnyx/node-db-migrate/blob/master/lib/commands/on-complete.js
Ok here I am again, wasn't able to reproduce this. But noticed you are missing the arrow in the function definition, guessing you wanted to use arrow functions?
Here is the migration I can run up and down adapted from your examples:
'use strict';
var dbm;
var type;
var seed;
var Promise = require('bluebird');
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db) {
return new Promise((resolve, reject) => {
resolve("success");
});
};
exports.down = function (db, callback) {
callback(null, "success");
};
exports._meta = {
"version": 1
};
No problems here though:
✘ tobi@tobi ~/foss/node-db-migrate master ● db-migrate --env mongo down
[INFO] Defaulting to running 1 down migration.
[INFO] Processed migration 20170111175028-test
[INFO] Done
tobi@tobi ~/foss/node-db-migrate master ● db-migrate --env mongo down
[INFO] Defaulting to running 1 down migration.
[INFO] No migrations to run
[INFO] Done
tobi@tobi ~/foss/node-db-migrate master ● db-migrate --env mongo up
[INFO] Processed migration 20170111175028-test
[INFO] Done
Can you tell me which version of the mongo driver you were using and which mongodb server version you're running?
And could you please also post a verbose run? Thank you
That's just a typo in the code above, my bad - I have updated my origin posting. My local code is actually correct.
I am using db-migrate-mongodb@1.1.4
# mongod --version
db version v3.4.1
git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016
allocator: system
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
# db-migrate down --verbose
[INFO] Detected and using the projects local version of db-migrate. '/Users/rwheale/Documents/bitovi/bitcentive/node_modules/db-migrate/index.js'
[INFO] Environment variable MONGODB_URIis empty!
[INFO] Using dev settings: { driver: 'mongodb',
hosts: [ { host: 'localhost', port: '27017' } ],
host: 'localhost',
port: '27017',
database: 'bitcentive' }
[INFO] Defaulting to running 1 down migration.
[INFO] require: db-migrate-mongodb
[INFO] connecting
[INFO] connected
[SQL] createCollection [ 'migrations' ]
[INFO] loading migrations from database
[SQL] find [ 'migrations' ]
[INFO] preparing to run down migration: 20170109181647-start-rate-end-rate-fields
[SQL] remove [ 'migrations' ]
[SQL] remove [ 'migrations' ]
[INFO] Processed migration 20170109181647-start-rate-end-rate-fields
[INFO] Done
Does the db-migrte down command also hang for you? Or is this one exiting correctly?
I hangs on both down
and `up. It only hangs when a migration actually runs successfully. Failures and no-migrations exit successfully.
@DesignByOnyx This is the project where the problem occurs? https://github.com/donejs/bitcentive
If yes I'm gonna have a look.
Yes :) - thanks.
Also, I created my own branch and tested my internals theory and it appears to work. Still testing.
doh - scratch that. The internals call was not the fix.
@DesignByOnyx Give me a moment npm installing :)
Hit me up on screenhero if you want to keep this thread clean - ryan@bitovi.com. Or provide another chat client that you prefer (gitter, slack, et al).
Also, the test uses force-exit
to make the process exit. Running db-migrate [up|down] --force-exit
solves the problem for me, though it doesn't feel right.
Don't have a screenhero account and they're invite only currently, but you may reach me at tobi@wizardtales.com which is my XMPP (jabber) id.
However, the problem is with the service you're calling. It does not close the socket, therefore node is not going to stop.
You can look stuff like this up with this:
console.log(process._getActiveHandles());
This is an undocumented command to list open handles which can help you to debug such stuff.
ah, ok - It must be because I am including our app which sets up sockets and such. The method I'm calling is directly on a mongoose Model - the sockets are just a side effect of loading our app. Thanks so much man, this is a problem we can solve on our end.
For anybody else experiencing the hanging issue, maybe due to something similar to our app, passing --force-exit
will run your migrations and exit the process when they are complete.
This would be a working fix though :)
'use strict';
const app = require('../src/app');
const denodeify = require('denodeify');
const mongoose = require('mongoose');
exports.up = function(db) {
const svc = app.service('/api/contribution_months');
const ContributionMonth = svc.Model;
const paths = ContributionMonth.schema.paths;
const update = denodeify(ContributionMonth.update.bind(ContributionMonth));
/**
* Example update direct to db
*/
return update({
startRate: { '$exists': false }
}, {
startRate: paths.startRate.defaultValue,
endRate: paths.endRate.defaultValue
})
// Temporary hack: https://github.com/db-migrate/node-db-migrate/issues/454
.then(() => {
mongoose.connections.forEach((connection) => {
connection.close();
});
});
/**
* Example update using feathers services
*/
// return svc.find({
// startRate: { '$exists': false }
// }).then(results => {
// const stack = [];
// results.forEach(item => {
// item.startRate = paths.startRate.defaultValue;
// item.endRate = paths.endRate.defaultValue;
// stack.push(svc.update(item._id, item));
// });
// return Promise.all(stack);
// });
};
exports.down = function(db) {
const svc = app.service('/api/contribution_months');
const ContributionMonth = svc.Model;
const paths = ContributionMonth.schema.paths;
const update = denodeify(ContributionMonth.update.bind(ContributionMonth));
return update({}, {
'$unset': { startRate: 1, endRate: 1 }
})
// Temporary hack: https://github.com/db-migrate/node-db-migrate/issues/454
.then(() => {
mongoose.connections.forEach((connection) => {
connection.close();
});
});
};
@DesignByOnyx No Problem :)
Just edited for you, guess you ment force-exit
not force-update
.
Feel free to reach out again if you should encounter any other problems.
And a last tip:
process._getActiveRequests();
This is another function (also not documented), which is the other case where a node application may be stuck if it is not an open fd.
@DesignByOnyx Closing here as solved, feel free to reach out any time again and good look you and your team with your project!
I am using
v.0.10.0-beta.20
and the mongodb driver.I have tied both the Promise and callback strategies, but the process just hangs.
The migration is actually running successfully but it doesn't ever "finish". The process does exit if there are no migrations to run, if the Promise is rejected, or if an error is passed to the callback. This is affecting us because it's not allowing us to chain commands (
db-migrate up && npm run verify-db
), also preventing Travis from completing. I don't mind submitting a PR if you can point me in the right direction. I don't know where to look right now.