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

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

Open
envygeeks opened this issue Feb 12, 2013 · 6 comments
Open

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

envygeeks opened this issue Feb 12, 2013 · 6 comments

Comments

@envygeeks
Copy link

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 envygeeks reopened this Feb 12, 2013
@richo
Copy link

richo commented Feb 12, 2013

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

@envygeeks
Copy link
Author

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

@richo
Copy link

richo commented Feb 12, 2013

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.

@envygeeks
Copy link
Author

@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.

@richo
Copy link

richo commented Feb 12, 2013

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.

@envygeeks
Copy link
Author

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.

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

2 participants