em-synchrony icon indicating copy to clipboard operation
em-synchrony copied to clipboard

em-synchrony retuns nil inside of Thin, with aget, without aget.

Open envygeeks opened this issue 12 years ago • 6 comments

def get
out=nil
  if !EventMachine.reactor_running?
    EventMachine.run do
      Fiber.new do
        out = Response.new(@url.dup.get)
        EventMachine.stop
      end.resume
    end
  else
    Fiber.new do
      out = Response.new(@url.dup.get)
    end.resume
  end
out
end

Running the above code in a Fiber in Pry works perfectly, running it inside of Thin results in an nil value, actually the oddest part is it replaces @url with nil so I had to start duping just so I could figure out what's going on, but I couldn't. Even when I run the examples from: https://github.com/igrigorik/em-http-request/blob/master/examples/fibered-http.rb inside of Thin, I get the same nil result. Am I doing it wrong?

envygeeks avatar Feb 12 '13 01:02 envygeeks

Can you replace out with an array and push values into it instead of setting a local variable?

richo avatar Feb 12 '13 03:02 richo

@richo what do you mean? I'll have to create a local no matter what even with an array.

envygeeks avatar Feb 12 '13 03:02 envygeeks

def get
  out = []
  if !EventMachine.reactor_running?
    EventMachine.run do
      Fiber.new do
        out << Response.new(@url.dup.get)
        EventMachine.stop
      end.resume
    end
  else
    Fiber.new do
      out << Response.new(@url.dup.get)
    end.resume
  end
  out.pop
end

Almost certainly barking up the wrong tree, I seem to recall there being some weird instance_exec magic that may be creating more scope than you're expecting.

This just guarantees that you're mutating the closed over out and definitely not creating a new one. I'm not really expecting it to the work, but it's the only thing that jumped out at me.

richo avatar Feb 12 '13 03:02 richo

@richo didn't work :( and I'm stuck in a crappy situation with this too because Unicorn just doesn't work out well for restarting on file change in development and I can't get Thin + EM to do http requests right, and Puma is broken on jRuby w/ SSL >.< sad day.

envygeeks avatar Feb 12 '13 03:02 envygeeks

You can cheat with unicorn, use Guard to send USR2 to the master every time there are fs changes with preload_app :false?

That's kinda shitty but it sounds like your best option right now. That said, unicorn and jruby sounds like Doing It Wrong.

richo avatar Feb 12 '13 03:02 richo

Trinidad+jRuby in production/staging -- Thin+MRI on development (my development)... puma came about so that we could kinda bring the two together with a server that works on both without me having to build in certain key pieces to account for Thin quirks... so the comment does seem out of place but it's fitting kinda.

envygeeks avatar Feb 12 '13 04:02 envygeeks