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

MongoDB Socket Exception breaks inserts #99

Open
tobyhede opened this issue Dec 25, 2011 · 6 comments
Open

MongoDB Socket Exception breaks inserts #99

tobyhede opened this issue Dec 25, 2011 · 6 comments

Comments

@tobyhede
Copy link

Run into a weird one.

I cannot insert when using 'em-synchrony/em-mongo' , but I can read.

My insert code is pretty much lifted from the specs:

EventMachine.synchrony do
  db = EM::Mongo::Connection.new("localhost", 27017).db('hot_test')
  collection = db.collection('test')

  collection.insert(:name => 'two', :position => 1)
  EventMachine.stop
end

I can insert using the 'regular' em-mongo gem with EventMachine.

I am seeing a SocketException in the mongo log.

Sun Dec 25 13:15:42 [initandlisten] connection accepted from 127.0.0.1:51392 #4
Sun Dec 25 13:15:42 [conn4] Socket recv() conn closed? 127.0.0.1:51392
Sun Dec 25 13:15:42 [conn4] SocketException: remote: 127.0.0.1:51392 error: 9001 socket exception [0] server [127.0.0.1:51392] 
Sun Dec 25 13:15:42 [conn4] end connection 127.0.0.1:51392

This Exception also occurs when reading, but the values the read works:

Sun Dec 25 13:13:37 [initandlisten] connection accepted from 127.0.0.1:51378 #2
Sun Dec 25 13:13:37 [conn2] runQuery called hot_test.test {}
Sun Dec 25 13:13:37 [conn2]    used cursor: 0x102603a70
Sun Dec 25 13:13:37 [conn2] query hot_test.test nreturned:1 reslen:70 0ms
Sun Dec 25 13:13:37 [conn2] Socket recv() conn closed? 127.0.0.1:51378
Sun Dec 25 13:13:37 [conn2] SocketException: remote: 127.0.0.1:51378 error: 9001 socket exception [0] server [127.0.0.1:51378]

Using MongoDB v2.0.1 on OS X.

@tobyhede
Copy link
Author

The plot thickens.

If I have a reference to collection.find in my code, everything suddenly works as expected.

So the following will do the insert:

EventMachine.synchrony do
  db = EM::Mongo::Connection.new("localhost", 27017).db('hot_test')
  collection = db.collection('test')

  collection.insert(:name => 'two', :position => 1)
  collection.find
  EventMachine.stop
end

If I remove collection.find, the insert does nothing.

In all cases I see the SocketException in the mongo log

@igrigorik
Copy link
Owner

Toby, currently em-synchrony only patches the find methods in em-mongo: https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/em-mongo.rb#L62

Sorry about the confusion with this.. Two things we can do: (a) extend the patch to more methods, or (b) for a "quick fix" you can use Synchrony.sync interface to make the insert operations behave as you would expect.

@igrigorik
Copy link
Owner

FYI: #98

@tobyhede
Copy link
Author

tobyhede commented Jan 2, 2012

Thanks for the info. Had me stumped, but eventually had discovered the missing methods and started my own implementation. May progress with this while keeping an eye on these other branches to see what I may be able to contribute.

@sujal
Copy link

sujal commented Jan 3, 2012

@tobyhede - I just updated my branch on that pull request with more functions wrapped or rewritten. Would love to both see your work and get your thoughts on the work I've done so far. As of right now, I'm close to code complete, am moving onto testing/bug fixing unless someone finds something wrong or broken.

We're going to try and put this into production soon (Weeks), so would love to get another set of eyes and or opinions into the mix.

Sujal

@igrigorik
Copy link
Owner

Any updates on this?

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

3 participants