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

Oplog driver failed to copy results bug #2033

Closed
paralin opened this Issue Apr 9, 2014 · 27 comments

Comments

Projects
None yet
@paralin

paralin commented Apr 9, 2014

I'm getting this error quite frequently (once every 20 minutes or so) on my meteor server:

Exception in defer callback: Error: failed to copy newResults in
to _published!
  at Error (<anonymous>)
  at _.extend._publishNewResults (packages/mongo-livedata/oplo
g_observe_driver.js:736)
  at _.extend._runQuery (packages/mongo-livedata/oplog_observe
_driver.js:619)
  at _.extend._runInitialQuery (packages/mongo-livedata/oplog_
observe_driver.js:555)
  at packages/mongo-livedata/oplog_observe_driver.js:157
  at packages/mongo-livedata/oplog_observe_driver.js:16
  at _.extend.withValue (packages/meteor/dynamics_nodejs.js:37
) 
  at packages/meteor/timers.js:6
  at runWithEnvironment (packages/meteor/dynamics_nodejs.js:89
) 

I'm not quite sure what causes it. I think it might be a Meteor bug.

@Slava

This comment has been minimized.

Member

Slava commented Apr 9, 2014

It is an assertion that fails. Any reproduction?

@paralin

This comment has been minimized.

paralin commented Apr 9, 2014

@Slava The app is quite complex, I'm not sure where to start. Any ideas?

@Slava

This comment has been minimized.

Member

Slava commented Apr 9, 2014

@kidovate what server-side observes or publications you have? That's the part that is important. Minimal repro would consist of one of those queries/publications and similar data model.

@glasser

This comment has been minimized.

Member

glasser commented Apr 10, 2014

Closing due to lack of reproduction. I'm definitely curious though and we'll reopen if it's reproducible.

@glasser glasser closed this Apr 10, 2014

@paralin

This comment has been minimized.

paralin commented Apr 10, 2014

I'm trying to pluck out all of the publications and subscriptions from my app that might cause something like this. I can't reproduce it yet although my app itself sometimes gets this error leaving one of the clients in a state where no additional data is pushed.

@evanyeung

This comment has been minimized.

evanyeung commented Apr 23, 2014

I was able to reproduce the error message if I publish extra user data with the selector 'Meteor.userId' instead of 'this.userId'.

eg. this gives me your error message

Meteor.publish('userData', function(){
    return Meteor.users.find({_id: Meteor.userId}, {fields: {extraField: 1}});
});

whereas this works fine

Meteor.publish('userData', function(){
    return Meteor.users.find({_id: this.userId}, {fields: {extraField: 1}});
});

This occurred on every server restart for me, however, but something similar could be causing your issue?

@paralin

This comment has been minimized.

paralin commented Apr 23, 2014

@evanyeung I'm not using Meteor.userId in publishes. It has to be something else, although, I think the issue now might just be some malfunctioning code in publishes. Maybe some better error messages are needed to trace the problem.

@glasser

This comment has been minimized.

Member

glasser commented Apr 24, 2014

@evanyeung Please see https://github.com/meteor/meteor/wiki/Contributing-to-Meteor#reporting-a-bug-in-meteor for advice on how to demonstrate a bug in a way that's useful for us to try to look into it. Code snippets are unfortunately rarely helpful without the full context.

@brentjanderson

This comment has been minimized.

brentjanderson commented May 3, 2014

I had this same issue, it was that I was passing a function rather than a string/number/other value to MongoDB. Once I added parentheses to the function so it actually executed, it started working immediately. @evanyeung, if you try the following (note the () with Meteor.userId()), does that produce the same issue?

Meteor.publish('userData', function(){
    return Meteor.users.find({_id: Meteor.userId()}, {fields: {extraField: 1}});
});
@kaytrance

This comment has been minimized.

kaytrance commented May 5, 2014

excellent, not I have this issue to.. It all started from messing with {reactive:false} in find() routine.. cannot figure out how to reproduce and revert back to normal working state.

@alprestedge

This comment has been minimized.

alprestedge commented May 13, 2014

I have this issue as well. Started occurring with this subscription:

if Meteor.isServer
  Meteor.startup ->
    Meteor.publish "organisations", () ->
      organisations.find {$or: [{ "ownerId": this.userId}, { "users.userId": { $in: [this.userId] } }]}

Strangely it gives the error only when I log out.. Once the error occurs I basically need to reset the DB. Hope this helps

Update: Narrowed down to:
Works fine:

if Meteor.isServer
  Meteor.startup ->
    Meteor.publish "organisations", () ->
      organisations.find {$or: [{ "ownerId": this.userId}, { "users.userId": { $in: [] } }]}

Breaks with error (only when you log out. When logged in this works also):

if Meteor.isServer
  Meteor.startup ->
    Meteor.publish "organisations", () ->
      organisations.find {$or: [{ "ownerId": this.userId}, { "users.userId": { $in: [this.userId] } }]}

Thanks @evanyeung , so i'm not losing my mind after all :D

@glasser

This comment has been minimized.

Member

glasser commented May 13, 2014

@evanyeung

This comment has been minimized.

evanyeung commented May 13, 2014

Here is a clonable reproduction using Meteor.userId inside of a publish function as per my earlier code snippets

https://github.com/evanyeung/meteor-oplog-driver-failed-to-copy-bug

@alprestedge

This comment has been minimized.

alprestedge commented May 20, 2014

@glasser So is this getting reopened then? or no? Much appreciated :D

@evanyeung

This comment has been minimized.

evanyeung commented May 20, 2014

@alprestedge I added a branch to https://github.com/evanyeung/meteor-oplog-driver-failed-to-copy-bug named alprestedge-bug. I did not have the error occur when using your code snippets. Was there anything else interacting with those code snippets that you didn't show? Give reproducing it with as little other code as possible a shot if you're still having problems with it.

Also note, the error I was recreating was just the same error message as given by @kidovate. In the meteor docs it does say not to use Meteor.userId() in publish functions as per http://docs.meteor.com/#meteor_userid

@glasser

This comment has been minimized.

Member

glasser commented May 24, 2014

I don't see an issue on the alprestedge-bug branch, and on master the issue is (as mentioned above) passing a function in the query.

This error message basically means that minimongo and MongoDB are disagreeing about how a selector works. In this case, it's because the Node Mongo driver drops functions from its queries by default, so it's running the "all docs" query {}. minimongo is running the {_id: someFunction} query which matches no docs.

Ideally we should have an EJSON.isEJSONValue function and use it at various places like selectors so as to get a better error message.

But I think the only bug here is that you're getting an internal error message rather than a helpful one.

@Sewdn

This comment has been minimized.

Sewdn commented Jul 16, 2014

I've been having this issue this evening.
My suggestion: check your data. The issue was triggered by querying documents with a faulty value in one of the fields used in the query's conditions.

My publication's query returns:
Events.find({'room._id': roomId, endedAt: {$exists: false}, startingAt: {$lt: tomorrow.getTime()}});

My collection had documents with a NaN value in the startingAt field (matching the 2 other criteria).

Hope this helps. Goog luck!

@looshi

This comment has been minimized.

looshi commented Aug 2, 2014

I had this same issue upon logout.
here's a cloneable reproduction. Since it depends on the state of data it is really hard to reproduce, but hopefully this reproduces it clearly enough :
https://github.com/davluzius/meteor-issue-2033

For me, it had to do with the mongo $or operation on an expression which is trying to match null array value. @alprestedge I think what might be happening is that when a user logs out, the Publish function is invoked, but "this.userId" value is null within your query's $or operation. I don't know if it's a good idea to check for null there in the Publish, that could supress other helpful errors that may crop up, but it would probably not throw the exception.

@sferoze

This comment has been minimized.

sferoze commented Aug 13, 2014

I have the same issue and it have no clue how to fix it. It just started happening after I threw an error after a database update.

Now I cannot login to my app anymore. Users that are already logged in can still move around the app, but reactivity is broken and user cannot sign in anymore.

And I have no clue how to fix it, only thing it to reset the database. But I hate having to do that.

@sferoze

This comment has been minimized.

sferoze commented Aug 13, 2014

I can resolve the issue whenever I reset the database so I believe the error is because some bad value was inserted into the database.

This error occurs when some operations writing to the database fails. While coding my app sometimes I make a mistake and get an error, it is not good that I have to reset my whole project because of this!

How can I fix this without resetting the database each time? Is there a way to delete all mongo documents created within the last hour or something?

@brentjanderson

This comment has been minimized.

brentjanderson commented Aug 13, 2014

If you use the 'meteor mongo' command in your project, you get direct access to the mongo database. From there, you can use db..find or .remove or .update or .insert like you would any collection in your code. This gives you complete control over how you explore and fix the problem in the future.

    1. 2014 v 23:31, sferoze notifications@github.com:

I can resolve the issue whenever I reset the database so I believe the error is because some bad value was inserted into the database.

This error occurs when some operations writing to the database fails. While coding my app sometimes I make a mistake and get an error, it is not good that I have to reset my whole project because of this!

How can I fix this without resetting the database each time? Is there a way to delete all mongo documents created within the last hour or something?


Reply to this email directly or view it on GitHub.

@sferoze

This comment has been minimized.

sferoze commented Aug 13, 2014

I knew about that but the issue is, I am not sure what operation made this error happen. I explored the recently created documents and everything looked ok. That why I wanted to know a way to delete all documents created within certain time period.

But it might not 100% be bad input into mongodb. I just cant tell, but I know when I reset the databse my app works fine. Until a database error happens again, then it breaks and noone can login anymore, and reactivity breaks until I reset meteor mongo

@sferoze

This comment has been minimized.

sferoze commented Aug 13, 2014

What is the best way for me to backup my current Meteor database, so that next time this happens, I can just restore it from backup, instead of starting all over again with blank data?

@looshi

This comment has been minimized.

looshi commented Aug 14, 2014

@sferoze

In my case it was happening due to this, searching within arrays of a collection object, using $or. Here "stuff" is an array
Projects.find( { $or: [ { name:'someName' }, { "stuff._id" : thing._id } ] } );

I fixed it by checking for null on values I was trying to match
if( thing && thing._id )
Projects.find( { $or: [ { name:'someName' }, { "stuff._id" : thing._id } ] } );

It sounds like you may be inserting null values into a collection, which some other query is depending on? This happened to me a lot in joins. Also, in Publish functions if you use "this.userId", make sure it's not null, that can cause issues on login / logout.

see my reproduction above, that may help.

@sferoze

This comment has been minimized.

sferoze commented Aug 14, 2014

Hi @davluzius

You are correct! I was meaning to update here as I figure out it was this.userId in the publish function which was null, in which querying mongodb with a null value produced this error!

So the issue was not inserting null values into the database, but rather querying mongodb with a null value (this.userId) in the publish function.

Now I just check for userId with (if this.userId !== null) then continue.

Now that I am thinking about it, inserting null values into mongodb should be ok, right?
Mongodb can handle null values I thought?

@maxharris9

This comment has been minimized.

maxharris9 commented Aug 15, 2014

This issue is affecting me as well. A better error message would be very helpful!

glasser added a commit that referenced this issue Sep 5, 2014

@glasser

This comment has been minimized.

Member

glasser commented Sep 5, 2014

As mentioned on #2244, the issue is that Mongo has inconsistency around how to treat queries of the form {'a.b': null}. I pushed a better error message.

glasser added a commit that referenced this issue Sep 5, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment