Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

MongoDB Socket Exception breaks inserts #99

Open
tobyhede opened this Issue · 6 comments

3 participants

Toby Hede Ilya Grigorik sujal
Toby Hede

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.

Toby Hede

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

Ilya Grigorik
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.

Ilya Grigorik
Owner

FYI: #98

Toby Hede

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

@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

Ilya Grigorik
Owner

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.