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

Mail catching smtp timeout when running in background #182

Closed
istvano opened this issue Dec 22, 2014 · 53 comments
Closed

Mail catching smtp timeout when running in background #182

istvano opened this issue Dec 22, 2014 · 53 comments

Comments

@istvano
Copy link

@istvano istvano commented Dec 22, 2014

Hi Guys,

I have a very strange issue but I do not how I could debug it any further.

1, if I run mailcatcher in the foreground -f -v

a, web interface works perfectly
b, smtp receives emails flawlessly

2, if I run it in the backgroud

a, web interface works
b, smtp interface does not respond.

Dec 22 12:34:24 sendemail[10247]: ERROR => Timeout while reading from localhost:2525 There was no response after 60 seconds.

If I want to telnet into it I CAN!

It is not a port issue as I run the test on the same computer and when it is in foreground mode it works.

I do not see any error logs anywhere. is there a way to enable some debug mode so that I can see why the smtp timeouts ?

Any idea what can be wrong ?

my ruby version is -> ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-linux]
my mailcatcher version is mailcatcher (0.5.12)

My local gems:
*** LOCAL GEMS ***

activesupport (3.2.19)
bigdecimal (1.1.0)
builder (3.2.2)
bundler (1.5.3)
chef (11.16.4)
chef-zero (2.2)
coderay (1.1.0)
daemons (1.1.9)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
eventmachine (1.0.4)
ffi (1.9.5)
ffi-yajl (1.1.0)
haml (4.0.6)
hashie (2.1.2)
highline (1.6.21)
i18n (0.6.11)
io-console (0.3)
ipaddress (0.8.0)
json (1.8.1, 1.5.5)
libyajl2 (1.0.1)
mail (2.6.3)
mailcatcher (0.5.12)
method_source (0.8.2)
mime-types (1.25.1)
minitest (2.5.1)
mixlib-authentication (1.3.0)
mixlib-cli (1.5.0)
mixlib-config (2.1.0)
mixlib-log (1.6.0)
mixlib-shellout (1.6.0)
multi_json (1.10.1)
mysql (2.9.1)
net-ssh (2.9.1)
net-ssh-gateway (1.2.0)
net-ssh-multi (1.2.0)
ohai (7.4.0)
plist (3.1.0)
pry (0.10.1)
rack (1.5.2)
rack-protection (1.5.3)
rake (10.1.1, 0.9.2.2)
rdoc (3.9.5)
rest-client (1.6.7)
rspec (2.14.1)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
rspec-mocks (2.14.6)
rspec_junit_formatter (0.1.6)
ruby-shadow (2.3.4)
simplecov (0.9.1)
simplecov-html (0.8.0)
sinatra (1.4.5)
skinny (0.2.3)
slop (3.6.0)
sqlite3 (1.3.10)
systemu (2.6.4)
thin (1.5.1)
tilt (1.4.1)
wmi-lite (1.0.0)

@istvano
Copy link
Author

@istvano istvano commented Dec 22, 2014

Please note I have tried different ports from 1025 like 2525 to see if this helps but. it does not. when running in daemon mode ( background ) the smtp does not work properly.

@cseeger
Copy link

@cseeger cseeger commented Dec 23, 2014

+1, same issue as described.

@AntoineAugusti
Copy link

@AntoineAugusti AntoineAugusti commented Dec 23, 2014

I think that it has something to do with the updated dependencies. Right, old and working ones. Left, new and not working ones.

http://puu.sh/dGlWf/cb4b0e8dd9.png

Temporary workaround: mailcatcher -f > out.txt&

@istvano
Copy link
Author

@istvano istvano commented Dec 23, 2014

Thanks for the info. I will try to run it in the foreground and put it into bg as you suggested

@rosstimson
Copy link

@rosstimson rosstimson commented Dec 23, 2014

We encountered this issue today, it cause much hair pulling :)

Running in foreground workaround fixed it for us.

@istvano
Copy link
Author

@istvano istvano commented Dec 23, 2014

Hi, I am changing my script to do this too. Although I was really worried as the only similar script is https://github.com/ian-kent/Go-MailHog and I really do not want to upgrade as in the project we use vagrant boxes for the devs and each has mailcatcher.

It would be nice to find out what breaks this. Unfortunatelly I am not a ruby guy and I can not see any log message anywherer.

Thanks

@r4m
Copy link

@r4m r4m commented Dec 23, 2014

+1

@yatsenko
Copy link

@yatsenko yatsenko commented Dec 24, 2014

I have the same issue. Ubuntu 14.04

@liuruting
Copy link

@liuruting liuruting commented Dec 24, 2014

+1, i am having the same issue as described.

@kevinsheffield
Copy link

@kevinsheffield kevinsheffield commented Dec 24, 2014

+1

@glebtv
Copy link

@glebtv glebtv commented Dec 25, 2014

Problem is Process.daemon here:
https://github.com/sj26/mailcatcher/blob/master/lib/mail_catcher.rb#L177
I think it should be used before calling EM.run
If I move Process.daemon to beginning of that file, it works

@bmishkin
Copy link

@bmishkin bmishkin commented Dec 29, 2014

+1, 0.5.12, ruby 2.1.5, OS X 10.10.1

running in foreground workaround works.

@vsubramanian
Copy link

@vsubramanian vsubramanian commented Dec 29, 2014

+1, 0.5.12, ruby 2.1.5, OS X 10.10.1

The foreground workaround works for me too.

@rubemz
Copy link

@rubemz rubemz commented Dec 29, 2014

+1, ruby 2.1.2p95, , OS X 10.10.1

The foreground workaround works for me.

@corykeane
Copy link

@corykeane corykeane commented Dec 30, 2014

+1 - super frustrating. Glad it at least works in the foreground.

@joshmanders
Copy link

@joshmanders joshmanders commented Dec 30, 2014

👍

2 similar comments
@adahl
Copy link

@adahl adahl commented Dec 30, 2014

+1

@benjaminwood
Copy link

@benjaminwood benjaminwood commented Dec 30, 2014

👍

@soullivaneuh
Copy link

@soullivaneuh soullivaneuh commented Jan 2, 2015

Exactly the same problem, and workaround.

In addition, if you run mailcatcher as daemon and try to quit from the interface, this will redirect you to mailcatcher homepage but won't kill the concerned process.

@soulim
Copy link

@soulim soulim commented Jan 4, 2015

Just got the same issue, and seems like it somehow depends on Ruby version.

The mailcatcher as a daemon doesn't work on Ruby 2.1.5p273, and everything works perfectly fine on Ruby 2.1.3p242.

I haven't changed anything on the project except Ruby version. The daemon stopped working after upgrade to Ruby 2.1.5.

@danlo
Copy link

@danlo danlo commented Jan 4, 2015

+1, I encountered this when upgrading from Rails 4.1.x to Rails 4.2. I traced it down to: net/smtp

The version of ruby remained the same: ruby 2.1.5p273

Right before it sends the email

# byebug break point
b /usr/local/lib/ruby/2.1.0/net/smtp.rb:555
c

Net Smtp id file (/usr/local/lib/ruby/2.1.0/net/smtp.rb:555)
# $Id: smtp.rb 45111 2014-02-22 05:39:58Z naruse $

Actual code

def do_start(helo_domain, user, secret, authtype)
  raise IOError, 'SMTP session already started' if @started
  if user or secret
    check_auth_method(authtype || DEFAULT_AUTH_TYPE)
    check_auth_args user, secret
  end
  s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
    tcp_socket(@address, @port)
  end
  logging "Connection opened: #{@address}:#{@port}"
  @socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
  check_response critical { recv_response() }  # <--- recv_response() doesn't get anything; ERGO; time out.

When running in the foreground (as above) the message received is:

"220 EventMachine SMTP Server"

When running in background mode; the message is not received

@danlo
Copy link

@danlo danlo commented Jan 4, 2015

I solved the problem for myself by installing eventmachine 1.0.3

 gem install eventmachine -v 1.0.3
 gem uninstall eventmachine -v 1.0.4

and then restarting mailcatcher.

@juukie
Copy link

@juukie juukie commented Jan 5, 2015

@danlo that worked for me too! 👍

@sgb-io
Copy link

@sgb-io sgb-io commented Jan 5, 2015

@danlo +1, also fixed for me

@benjaminwood
Copy link

@benjaminwood benjaminwood commented Jan 5, 2015

Thanks @danlo, that does the trick!

@eikes
Copy link

@eikes eikes commented Jan 5, 2015

👍 @danlo

2 similar comments
@drmikecrowe
Copy link

@drmikecrowe drmikecrowe commented Jan 6, 2015

👍 @danlo

@kyleries
Copy link

@kyleries kyleries commented Jan 7, 2015

👍 @danlo

@davidochoa
Copy link

@davidochoa davidochoa commented Jan 12, 2015

👍 @danlo, thanks!

@klein0r
Copy link

@klein0r klein0r commented Jan 15, 2015

Nice solution @danlo ! Thanks!

@sj26
Copy link
Owner

@sj26 sj26 commented Jan 17, 2015

Seems to be a bug in the latest version of EventMachine, sadly. -.-

The reason it doesn't daemonise until after the eventmachine loop is running is so that port failures can be reported to the user.

I'll see what's going on upstream in eventmachine. But honestly eventmachine has become a major pain. May see if there's a feasible alternative, maybe even going back to the standard library with a custom select loop.

@BelkinaDasha
Copy link

@BelkinaDasha BelkinaDasha commented Jan 19, 2015

@danlo, Thank you soo much!

@alextakitani
Copy link

@alextakitani alextakitani commented Jan 21, 2015

@danlo, Thank you!!!

@danlo
Copy link

@danlo danlo commented Jan 23, 2015

@sj26 Someone mentioned on another thread; but could we have a new release of the existing code, but just forcing event machine at 1.0.3?

@davidahopp
Copy link

@davidahopp davidahopp commented Jan 26, 2015

I issued a pull request as a temporary fix that forces the version of eventmachine to be less than 1.0.4. If that is not used, eventmachine will default install 1.0.4 which will cause the timeout issue

@sj26
Copy link
Owner

@sj26 sj26 commented Jan 27, 2015

This does seem to be an eventmachine regression.

Please try mailcatcher 0.6.0pre1 (gem install mailcatcher --pre) which restricts eventmachine to != 1.0.4. This is only a temporary release until I can fix the eventmachine problem to fix ruby 2.2 compatiblity, or replace eventmachine with something else.

@felixbuenemann
Copy link

@felixbuenemann felixbuenemann commented Jan 28, 2015

@chrishough eventmachine 1.0.3 is not compatible with ruby 2.2, so you need to use ruby 2.1 or older.

@matthewbarram
Copy link

@matthewbarram matthewbarram commented Jan 29, 2015

I have the same issue. Running as mailcatcher -f works for me too.

@sj26
Copy link
Owner

@sj26 sj26 commented Jan 29, 2015

@matthewbarram please try mailcatcher 0.6.0pre1 (gem install mailcatcher --pre).

@JackEllis
Copy link

@JackEllis JackEllis commented Jan 29, 2015

@sj26 Just came to report this exact bug. Brought in the 0.0.0pre1, as you suggested, and I can now run it fine without --foreground - thank you 👍

@sj26
Copy link
Owner

@sj26 sj26 commented Jan 29, 2015

This has been worked around in 0.6.0, please upgrade with gem install mailcatcher.

The root cause of this has also been lodged as an issue upstream:

eventmachine/eventmachine#569

@sj26 sj26 closed this Jan 29, 2015
@BrizzleRocker
Copy link

@BrizzleRocker BrizzleRocker commented Feb 3, 2015

@sj26 Sorry to jump-start this again but I don't think it's fixed and having spent the best part of 4 hours of unpaid work playing with this I'm cross! This was a completely clean install this morning.

ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

Clean install today and updated to 0.6.0
*** LOCAL GEMS ***

activesupport (4.2.0)
daemons (1.1.9)
eventmachine (1.0.5)
i18n (0.7.0)
json (1.8.2)
mail (2.6.3)
mailcatcher (0.6.0)
mime-types (2.4.3)
minitest (5.5.1)
rack (1.6.0)
rack-protection (1.5.3)
sinatra (1.4.5)
skinny (0.2.3)
sqlite3 (1.3.10)
thin (1.5.1)
thread_safe (0.3.4)
tilt (1.4.1)
tzinfo (1.2.2)

It's working with the -f -v options but nada in the background.

/usr/lib/ruby/1.9.1/net/protocol.rb:146:in rescue in rbuf_fill': Timeout::Error (Timeout::Error) from /usr/lib/ruby/1.9.1/net/protocol.rb:140:inrbuf_fill'
from /usr/lib/ruby/1.9.1/net/protocol.rb:122:in readuntil' from /usr/lib/ruby/1.9.1/net/protocol.rb:132:inreadline'
from /usr/lib/ruby/1.9.1/net/smtp.rb:929:in recv_response' from /usr/lib/ruby/1.9.1/net/smtp.rb:552:inblock in do_start'
from /usr/lib/ruby/1.9.1/net/smtp.rb:939:in critical' from /usr/lib/ruby/1.9.1/net/smtp.rb:552:indo_start'
from /usr/lib/ruby/1.9.1/net/smtp.rb:519:in start' from /var/lib/gems/1.9.1/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:indeliver!'
from /var/lib/gems/1.9.1/gems/mail-2.6.3/lib/mail/message.rb:2141:in do_delivery' from /var/lib/gems/1.9.1/gems/mail-2.6.3/lib/mail/message.rb:238:indeliver'
from /var/lib/gems/1.9.1/gems/mailcatcher-0.6.0/bin/catchmail:71:in <top (required)>' from /usr/local/bin/catchmail:23:inload'
from /usr/local/bin/catchmail:23:in `

'

@sj26
Copy link
Owner

@sj26 sj26 commented Feb 3, 2015

Ah, I see:

eventmachine (1.0.5)

They must have released a new version which has broken my fix. I'll look into it again.

@ianks
Copy link

@ianks ianks commented Feb 3, 2015

👍

@sj26
Copy link
Owner

@sj26 sj26 commented Feb 3, 2015

mailcatcher 0.6.1 is out which works with eventmachine up to 1.0.5, and restricts future upgrades.

@BrizzleRocker
Copy link

@BrizzleRocker BrizzleRocker commented Feb 4, 2015

@sj26 downloading now and will report back, many thanks for monitoring this, great response.

@BrizzleRocker
Copy link

@BrizzleRocker BrizzleRocker commented Feb 4, 2015

@sj26 It works! Thanks again for your timely update.

@sebasjimenez10
Copy link

@sebasjimenez10 sebasjimenez10 commented Sep 11, 2015

@danlo 👍

@jmnewman
Copy link

@jmnewman jmnewman commented Mar 8, 2016

not sure if this is still open, but I am running into this problem where mailcatcher has stopped working. Nothing that I know of has changed (other than switching between a lot of branches) and I can't find any error messages showing where something might be breaking. right now in development I can see the emails being sent in the logs, but they're not popping up in mailcatcher. here's my set up

  • Rails 4.2.6
  • ruby 2.2.2p95
  • mailcatcher 0.6.4

I have tried @danlo tip and it didn't work (ended with a result similar to @chrishough) and tried running with mailcatcher -f -v and installing gem install mailcatcher --pre and still am not getting it to work. are there any other workarounds?

@pedro-stanaka
Copy link

@pedro-stanaka pedro-stanaka commented Apr 21, 2016

I still have this problem, only able to use it in foreground. Otherwise it simply crashes the smtp interface.
I'm using:

  • ruby 2.3.0p0 (with rvm)
  • mailcatcher 0.6.4
  • eventmachine 1.0.9.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.