<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -11,9 +11,11 @@ module NeverBlock
           @fiber = Fiber.current
           #puts &quot;&gt;&gt;&gt;&gt;&gt;register_with_event_loop fiber #{@fiber.inspect}&quot;
           # When there's no previous em_connection
-          unless @fiber[em_connection_with_pool_key]
-            @fiber[em_connection_with_pool_key] = EM::attach(socket,EMConnectionHandler,self)
+          key = em_connection_with_pool_key
+          unless @fiber[key]
+            @fiber[key] = EM::attach(socket,EMConnectionHandler,self)
             @fiber[:callbacks] &lt;&lt; self.method(:unregister_from_event_loop)
+            @fiber[:em_keys] &lt;&lt; key
           end
         else
           raise ::NB::NBError.new(&quot;FiberedDBConnection: EventMachine reactor not running&quot;)
@@ -23,9 +25,10 @@ module NeverBlock
       # Unattaches the connection socket from the event loop
       def unregister_from_event_loop
         #puts &quot;&gt;&gt;&gt;&gt;&gt;unregister_from_event_loop #{self.inspect} #{@fiber.inspect}&quot;
-        if em_c = @fiber[em_connection_with_pool_key]
+        key = @fiber[:em_keys].pop
+        if em_c = @fiber[key]
           em_c.detach
-          @fiber[em_connection_with_pool_key] = nil
+          @fiber[key] = nil
           true
         else
           false
@@ -41,7 +44,8 @@ module NeverBlock
 
       # Closes the connection using event loop
       def event_loop_connection_close
-        @fiber[em_connection_with_pool_key].close_connection if @fiber[em_connection_with_pool_key]
+        key = em_connection_with_pool_key
+        @fiber[key].close_connection if @fiber[key]
       end
            
       # The callback, this is called whenever</diff>
      <filename>lib/never_block/db/fibered_db_connection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -48,6 +48,7 @@ module NeverBlock
             end
           end
           fiber[:callbacks] = []
+          fiber[:em_keys] = []
           fiber[:neverblock] = true
           @fibers &lt;&lt; fiber
         end</diff>
      <filename>lib/never_block/pool/fiber_pool.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0a09a7e06af2e2d315e4094e98a566899618b5f0</id>
    </parent>
  </parents>
  <author>
    <name>Stephen Sykes</name>
    <email>sds@Macintosh-40.(none)</email>
  </author>
  <url>http://github.com/espace/neverblock/commit/ae7d4cc26d52e578dee65bff01991cb40d1e592b</url>
  <id>ae7d4cc26d52e578dee65bff01991cb40d1e592b</id>
  <committed-date>2008-12-04T03:51:21-08:00</committed-date>
  <authored-date>2008-12-04T03:51:21-08:00</authored-date>
  <message>Fix crash due to wrong EM connection being detatched from</message>
  <tree>39504811490542fc3479818d922f2ea570b85e6b</tree>
  <committer>
    <name>Stephen Sykes</name>
    <email>sds@Macintosh-40.(none)</email>
  </committer>
</commit>
