tristandunn / pusher-fake

A fake Pusher server for development and testing.
https://rubygems.org/gems/pusher-fake
MIT License
173 stars 32 forks source link

start_tcp_server': no acceptor (port is in use or requires root privileges) #30

Closed lpender closed 10 years ago

lpender commented 10 years ago

Hi,

I know I've opened quite a few issues in the last few days. Don't want to hog the microphone, but I thought this might be helpful to you.

I am trying to use PusherFake in my development environment, though I'm not sure if that's intended usage.

Note: I made this change to server.rb:37, as part of my debugging process

-      Thin::Logging.silent = true
+      Thin::Logging.silent = false

Here are my local files:

development.rb

Pusher.key = ENV["PUSHER_KEY"]
Pusher.app_id = ENV["PUSHER_APP_ID"]
Pusher.secret = ENV["PUSHER_SECRET"]

PusherFake.configure do |configuration|
  configuration.web_options[:port] = 1976
end

require "pusher-fake/support/base"

And here is the result that I get in my server logs (it returns similar result for any open port)

https://gist.github.com/lpender/148700fc8d98e6ab4cbd

A couple more points of interest:

  1. I have to change the port every time I reset the server or it won't work.
  2. Given that I do change the port on server reset, the server seems to still work, asynchronously triggering events, even when disconnected from the internet.
  3. I receive this message when exiting foreman with Ctrl-D
18:17:04 web.1         | /Users/lpender/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pusher-fake-1.1.0/lib/pusher-fake/support/base.rb:16:in `kill': No such process (Errno::ESRCH)
18:17:04 web.1         |    from /Users/lpender/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pusher-fake-1.1.0/lib/pusher-fake/support/base.rb:16:in `block (2 levels) in <top (required)>'
18:17:04 web.1         | /Users/lpender/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pusher-fake-1.1.0/lib/pusher-fake/support/base.rb:16:in `kill': No such process (Errno::ESRCH)
18:17:04 web.1         |    from /Users/lpender/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pusher-fake-1.1.0/lib/pusher-fake/support/base.rb:16:in `block (2 levels) in <top (required)>'
18:17:04 web.1         | /Users/lpender/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pusher-fake-1.1.0/lib/pusher-fake/support/base.rb:16:in `kill': No such process (Errno::ESRCH)
18:17:04 web.1         |    from /Users/lpender/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/pusher-fake-1.1.0/lib/pusher-fake/support/base.rb:16:in `block (2 levels) in <top (required)>'
tristandunn commented 10 years ago

Sorry I'm slow on responding or looking into the issues. (I'm currently on vacation.)

My guess is the fake server isn't being killed before or after the server is shutdown for some reason. Did you check to see if there are any stray Ruby processes running after?

lpender commented 10 years ago

No worries, thanks for responding at all!

Thanks for the suggestion, I do see lingering ruby processes and kill them now, which is helpful.

That said, I don't think I'm getting to the underlying problem.

I'm starting to think that my approach is fundamentally wrong in trying to use PusherFake in the development environment.

I am trying to do this because my RSpec tests are failing (though I tried my best to translate them from your Cucumber tests), and I want to see if I can reproduce their failures in the development environment.

I've forked your pusher-fake-example repository and added two commits:

1) Update dependencies to the latest. 2) Attempt to use PusherFake in development.

The second commit doesn't work for me, it gives me the message Bad request: Unknown path: /apps/PUSHER_APP_ID/events when I visit localhost:3000.

I'd love it if you had time to take a look at the second commit and tell me if I have an error in my reasoning, or if you think that PusherFake simply shouldn't be used in development.

Thanks! -Lee

lpender commented 10 years ago

I figured out the problem: PusherFake is being started in both my web and my worker processes from my Procfile. Still working on a solution...

tristandunn commented 10 years ago

Ah dang. Only quick solution I can think of is to add an environment flag to one process line and only run it when set, but maybe a little bit of a hack.

lpender commented 10 years ago

Thinking it would be nice to be able to start the PusherFake server as its own rake task, but still struggling with the implementation...

lpender commented 10 years ago

In retrospect, I think the rake task is unlikely because of the cross-talk required between Pusher and Pusher-Fake...

That said, this seems to fix the issue:

config/initializers/pusher.rb

if Rails.env.development? && ENV["IS_WEB_DYNO"]
  require "pusher-fake/support/base"
end

Procfile

web: IS_WEB_DYNO=TRUE bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
...

Also, a caveat is that it appears that I have to log out/log back in to each account after restarting the server for it to work properly.

Thanks! -Lee

tristandunn commented 10 years ago

I'd like a better way to support this, since my intentions are for it to work in development, but I'm still not sure of a better solution than this. I made a note of your solution in the README. (354134a3984339dea11a0cf7b5faef783ec885bf) Going to close this for now, but feel free to reopen if you find a better solution.

Also, a caveat is that it appears that I have to log out/log back in to each account after restarting the server for it to work properly.

I assume that's because the connection and user information is lost when it's restarted.