Happens in 5.8.5, but not in 5.8.3
Do you want to request a feature or report a bug?
BUG
What is the current behavior?
Modifying several nested paths within arrays and calling the root-document's save method results in an validation error: "Can't validate() the same doc multiple times in parallel."
If the current behavior is a bug, please provide the steps to reproduce.
Not really sure tbh, it is consistent, but I don't have the time to create a sample that exhibits the behavior. Please note, we are only calling save once with an await and are not calling validate ourselves.
What is the expected behavior?
The object should be saved successfully as it was in 5.8.3.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: v8.15.0
MongoDB: 4.2.2
FULL EXCEPTION DUMP:
Unhandled Rejection at [object Promise]: { ValidationError: prospect validation failed: quotes.1.versions.21.terms.0.usageSummary: Can't validate() the same doc multiple times in parallel. Document: 5e14bef17bdb101633602aa6, quotes.1.versions.21.terms.1.usageSummary: Can't validate() the same doc multiple times in parallel. Document: 5e14bef17bdb101633602acc, quotes.1.versions.21.terms.3.usageSummary: Can't validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602afe, quotes.1.versions.21.terms.2.usageSummary: Can't validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602b3c, quotes.1.versions.21.usageSummary: Can't validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602b70
at ValidationError.inspect (/.../node_modules/mongoose/lib/error/validation.js:61:24)
at formatValue (util.js:399:38)
at inspect (util.js:293:10)
at Object.format (util.js:160:12)
at Object.inspect (/.../node_modules/log4js/lib/layouts.js:36:66)
at formatValue (util.js:399:38)
at inspect (util.js:293:10)
at Object.format (util.js:222:18)
at formatLogData (/.../node_modules/log4js/lib/layouts.js:55:22)
at colouredLayout (/.../node_modules/log4js/lib/layouts.js:130:7)
at /.../node_modules/log4js/lib/appenders/stdout.js:5:29
at appenders.forEach (/.../node_modules/log4js/lib/log4js.js:142:5)
at Array.forEach (
at Logger.sendLogEventToAppender [as dispatch] (/.../node_modules/log4js/lib/log4js.js:141:13)
at Logger._log (/.../node_modules/log4js/lib/logger.js:95:12)
at Logger.(anonymous function) [as error] (/.../node_modules/log4js/lib/logger.js:127:14)
at process.Application.process.on (/.../Application.js:61:35)
at emitTwo (events.js:126:13)
at process.emit (events.js:214:7)
at methodName (/.../node_modules/bluebird/js/release/debuggability.js:186:33)
at activeFireEvent (/.../node_modules/bluebird/js/release/debuggability.js:229:44)
at fireRejectionEvent (/.../node_modules/bluebird/js/release/debuggability.js:614:14)
at Promise._notifyUnhandledRejection (/.../node_modules/bluebird/js/release/debuggability.js:61:9)
at Async._drainQueue (/.../node_modules/bluebird/js/release/async.js:138:12)
at Async._drainQueues (/.../node_modules/bluebird/js/release/async.js:146:10)
at Immediate.Async.drainQueues (/.../node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
errors:
{ 'quotes.1.versions.21.terms.0.usageSummary':
{ ParallelValidateError: Can't validate() the same doc multiple times in parallel. Document: 5e14bef17bdb101633602aa6
at ParallelValidateError.MongooseError [as constructor] (/.../node_modules/mongoose/lib/error/mongooseError.js:10:11)
at new ParallelValidateError (/.../node_modules/mongoose/lib/error/parallelValidate.js:18:17)
at SingleNested.Document.validate (/.../node_modules/mongoose/lib/document.js:2033:24)
at /.../node_modules/mongoose/lib/schema/SingleNestedPath.js:252:11
at SingleNestedPath.SchemaType.doValidate (/.../node_modules/mongoose/lib/schematype.js:1046:12)
at SingleNestedPath.doValidate (/.../node_modules/mongoose/lib/schema/SingleNestedPath.js:244:35)
at /.../node_modules/mongoose/lib/document.js:2323:9
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
message: 'Can\'t validate() the same doc multiple times in parallel. Document: 5e14bef17bdb101633602aa6',
name: 'ParallelValidateError' },
'quotes.1.versions.21.terms.1.usageSummary':
{ ParallelValidateError: Can't validate() the same doc multiple times in parallel. Document: 5e14bef17bdb101633602acc
at ParallelValidateError.MongooseError [as constructor] (/.../node_modules/mongoose/lib/error/mongooseError.js:10:11)
at new ParallelValidateError (/.../node_modules/mongoose/lib/error/parallelValidate.js:18:17)
at SingleNested.Document.validate (/.../node_modules/mongoose/lib/document.js:2033:24)
at /.../node_modules/mongoose/lib/schema/SingleNestedPath.js:252:11
at SingleNestedPath.SchemaType.doValidate (/.../node_modules/mongoose/lib/schematype.js:1046:12)
at SingleNestedPath.doValidate (/.../node_modules/mongoose/lib/schema/SingleNestedPath.js:244:35)
at /.../node_modules/mongoose/lib/document.js:2323:9
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
message: 'Can\'t validate() the same doc multiple times in parallel. Document: 5e14bef17bdb101633602acc',
name: 'ParallelValidateError' },
'quotes.1.versions.21.terms.3.usageSummary':
{ ParallelValidateError: Can't validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602afe
at ParallelValidateError.MongooseError [as constructor] (/.../node_modules/mongoose/lib/error/mongooseError.js:10:11)
at new ParallelValidateError (/.../node_modules/mongoose/lib/error/parallelValidate.js:18:17)
at SingleNested.Document.validate (/.../node_modules/mongoose/lib/document.js:2033:24)
at /.../node_modules/mongoose/lib/schema/SingleNestedPath.js:252:11
at SingleNestedPath.SchemaType.doValidate (/.../node_modules/mongoose/lib/schematype.js:1046:12)
at SingleNestedPath.doValidate (/.../node_modules/mongoose/lib/schema/SingleNestedPath.js:244:35)
at /.../node_modules/mongoose/lib/document.js:2323:9
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
message: 'Can\'t validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602afe',
name: 'ParallelValidateError' },
'quotes.1.versions.21.terms.2.usageSummary':
{ ParallelValidateError: Can't validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602b3c
at ParallelValidateError.MongooseError [as constructor] (/.../node_modules/mongoose/lib/error/mongooseError.js:10:11)
at new ParallelValidateError (/.../node_modules/mongoose/lib/error/parallelValidate.js:18:17)
at SingleNested.Document.validate (/.../node_modules/mongoose/lib/document.js:2033:24)
at /.../node_modules/mongoose/lib/schema/SingleNestedPath.js:252:11
at SingleNestedPath.SchemaType.doValidate (/.../node_modules/mongoose/lib/schematype.js:1046:12)
at SingleNestedPath.doValidate (/.../node_modules/mongoose/lib/schema/SingleNestedPath.js:244:35)
at /.../node_modules/mongoose/lib/document.js:2323:9
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
message: 'Can\'t validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602b3c',
name: 'ParallelValidateError' },
'quotes.1.versions.21.usageSummary':
{ ParallelValidateError: Can't validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602b70
at ParallelValidateError.MongooseError [as constructor] (/.../node_modules/mongoose/lib/error/mongooseError.js:10:11)
at new ParallelValidateError (/.../node_modules/mongoose/lib/error/parallelValidate.js:18:17)
at SingleNested.Document.validate (/.../node_modules/mongoose/lib/document.js:2033:24)
at /.../node_modules/mongoose/lib/schema/SingleNestedPath.js:252:11
at SingleNestedPath.SchemaType.doValidate (/.../node_modules/mongoose/lib/schematype.js:1046:12)
at SingleNestedPath.doValidate (/.../node_modules/mongoose/lib/schema/SingleNestedPath.js:244:35)
at /.../node_modules/mongoose/lib/document.js:2323:9
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
message: 'Can\'t validate() the same doc multiple times in parallel. Document: 5e14bef27bdb101633602b70',
name: 'ParallelValidateError' } },
_message: 'prospect validation failed',
name: 'ValidationError' }
We currently have the same issue and I created a small sample code, that works with 5.8.4 and crashes with 5.8.5:
const mongoose = require('mongoose')
const schema = new mongoose.Schema({
id: String,
foo: {
bar: new mongoose.Schema({
baz: new mongoose.Schema({
i: Number,
}),
}),
},
})
const Model = mongoose.model('Model', schema)
async function run() {
mongoose.Promise = Promise
mongoose.connect('mongodb://localhost:27017/db', {
promiseLibrary: Promise,
useNewUrlParser: true,
useUnifiedTopology: true,
})
await new Promise(res => {
mongoose.connection.on('connected', res)
})
await Model.deleteMany({})
const a = new Model({ id: 'foo' })
await a.save()
const newData = {
"bar": {
"baz": {
"i": 1,
}
}
}
const b = await Model.findOne({ id: 'foo' })
b.foo = newData
await b.save()
}
run()
.then(console.log)
.catch(console.error)
I hope it's not too much foo, bar, baz... but I tried to keep it as simple as possible:
Error [ValidationError]: Model validation failed: foo.bar.baz: Can't validate() the same doc multiple times in parallel. Document: 5e175d98b8926f6c1607642f, foo.bar: Validation failed: baz: Can't validate() the same doc multiple times in parallel. Document: 5e175d98b8926f6c1607642f
at ValidationError.inspect (/src/node_modules/mongoose/lib/error/validation.js:61:24)
at formatValue (internal/util/inspect.js:690:31)
at inspect (internal/util/inspect.js:259:10)
at formatWithOptionsInternal (internal/util/inspect.js:1875:40)
at formatWithOptions (internal/util/inspect.js:1759:10)
at Object.Console.<computed> (internal/console/constructor.js:289:10)
at Object.warn (internal/console/constructor.js:299:61)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
errors: {
'foo.bar.baz': MongooseError [ParallelValidateError]: Can't validate() the same doc multiple times in parallel. Document: 5e175d98b8926f6c1607642f
at ParallelValidateError.MongooseError [as constructor] (/src/node_modules/mongoose/lib/error/mongooseError.js:10:11)
at new ParallelValidateError (/src/node_modules/mongoose/lib/error/parallelValidate.js:18:17)
at SingleNested.Document.validate (/src/node_modules/mongoose/lib/document.js:2033:24)
at /src/node_modules/mongoose/lib/schema/SingleNestedPath.js:252:11
at SingleNestedPath.SchemaType.doValidate (/src/node_modules/mongoose/lib/schematype.js:1046:12)
at SingleNestedPath.doValidate (/src/node_modules/mongoose/lib/schema/SingleNestedPath.js:244:35)
at /src/node_modules/mongoose/lib/document.js:2323:9
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
message: "Can't validate() the same doc multiple times in parallel. Document: 5e175d98b8926f6c1607642f",
name: 'ParallelValidateError'
},
'foo.bar': Error [ValidationError]: Validation failed: baz: Can't validate() the same doc multiple times in parallel. Document: 5e175d98b8926f6c1607642f
at ValidationError.inspect (/src/node_modules/mongoose/lib/error/validation.js:61:24)
at formatValue (internal/util/inspect.js:690:31)
at formatProperty (internal/util/inspect.js:1560:11)
at formatRaw (internal/util/inspect.js:940:9)
at formatValue (internal/util/inspect.js:718:10)
at formatProperty (internal/util/inspect.js:1560:11)
at formatRaw (internal/util/inspect.js:940:9)
at formatValue (internal/util/inspect.js:718:10)
at formatValue (internal/util/inspect.js:695:18)
at inspect (internal/util/inspect.js:259:10)
at formatWithOptionsInternal (internal/util/inspect.js:1875:40)
at formatWithOptions (internal/util/inspect.js:1759:10)
at Object.Console.<computed> (internal/console/constructor.js:289:10)
at Object.warn (internal/console/constructor.js:299:61)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
errors: [Object],
_message: 'Validation failed',
name: 'ValidationError'
}
},
_message: 'Model validation failed',
name: 'ValidationError'
}
It's working on one schema nested into another, but not with multiple nested Schema - maybe that helps.
Facing the same issue with 5.8.5, While saving deeply nested document.
Found the issue and fixed it, thanks for the repro script. Fix will be in v5.8.8, sorry for the trouble :+1:
I'm still seeing this in 5.8.9; last worked in 5.8.4.
I am trying to come up with a repro case - the above does not fail, not surprisingly. Complicating things is that I'm using feathers-mongoose on top of this, so not sure there isn't something broken there with latest.
The error I get back is
actions: Can't validate() the same doc multiple times in parallel. Document: 5e27491718d2be916be99db7, item.actions: Validation failed: access: Can't validate() the same doc multiple times in parallel. Document: 5e27491718d2be916be99db8
I can't paste the whole update document here. The model contains a child "item" which contains a child "actions". There are changes in the "actions" sub-document as well as within the "item" document itself. Further down these documents are multiple arrays, which seems to possibly be related.
Can you provide any pointers on how to try and troubleshoot the parallel validation error?
same with 5.8.9
Also seeing this issue on 5.8.9.
EDIT: As some others have mentioned, the last version without this issue is 5.8.4
The original repro script passes on 5.8.9, but using schemas with deeply nested subdocuments in arrays encounters the same "Can't validate() ... parallel" error:
const mongoose = require('mongoose');
const { Schema, Types } = mongoose;
const annotationsSchema = new Schema({ test: Schema.Types.String });
const versionSchema = new Schema({ annotations: annotationsSchema });
const slotSchema = new Schema({ versions: [versionSchema] });
const childSchema = new Schema({ slots: [slotSchema] });
const rootModelSchema = new Schema({ children: [childSchema] });
const Model = mongoose.model('Model', rootModelSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017/mongoose_test', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
await Model.deleteMany({});
const ID = new Types.ObjectId();
const a = new Model({
_id: ID,
children: [
{
slots: [{ versions: [] }],
},
],
});
await a.save();
const b = await Model.findById(ID);
const slot = b.children[0].slots[0];
slot.versions.push({
annotations: {
test: 'test',
},
});
await b.save();
}
run()
.then(() => console.log('OK'))
// Model validation failed: children.0.slots.0.versions.0.annotations: Can't validate() the same doc multiple times in parallel
.catch(console.error)
.finally(mongoose.disconnect);
It's possible there is a simpler way to reproduce it; this example comes from our failing use-case's structure.
@vkarpov15 should we open a new issue to track these ongoing problems, or do you want to re-open this one?
This is almost certainly related to #8531 which is fixed by #8532
Most helpful comment
Found the issue and fixed it, thanks for the repro script. Fix will be in v5.8.8, sorry for the trouble :+1: