stompgem / stomp

A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support.
http://stomp.github.com
Apache License 2.0
152 stars 80 forks source link

stdout polluted with stack trace #161

Closed thiagoxvo closed 4 years ago

thiagoxvo commented 4 years ago

Hi, I am using your library and I am facing an issue and before trying to open a PR I would like to understand if it is a problem or if it was the intention to keep the things like it is.

So, the main problem is: 1 - I am instantiating a reliable client configured for let's say server_1 and server_2 2 - As soon as my server_1 stop to work, the next time I try to publish a message it will fallback to server_2 3 - The problem is before it connects in server_2 it will try to connect in server_1 which will raise a timeout exception which currently is being logged to $stdout here

This creates lots of noise in my logs every time a new message is published after the switch toserver_2:

Sending message 8
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/netio.rb:424:in `initialize'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/netio.rb:424:in `open'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/netio.rb:424:in `block in open_ssl_socket'
/usr/local/lib/ruby/2.6.0/timeout.rb:76:in `timeout'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/netio.rb:423:in `open_ssl_socket'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/netio.rb:483:in `open_socket'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/utils.rb:116:in `block in socket'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/utils.rb:109:in `synchronize'
/usr/local/bundle/gems/stomp-1.4.8/lib/connection/utils.rb:109:in `socket'
/usr/local/bundle/gems/stomp-1.4.8/lib/stomp/connection.rb:173:in `initialize'
/usr/local/bundle/gems/stomp-1.4.8/lib/stomp/client.rb:134:in `new'
/usr/local/bundle/gems/stomp-1.4.8/lib/stomp/client.rb:134:in `create_connection'
/usr/local/bundle/gems/stomp-1.4.8/lib/stomp/client.rb:101:in `block in initialize'
/usr/local/lib/ruby/2.6.0/timeout.rb:76:in `timeout'
/usr/local/bundle/gems/stomp-1.4.8/lib/stomp/client.rb:99:in `initialize'
/opt/app/src/client.rb:11:in `new'
/opt/app/src/client.rb:11:in `create'
/opt/app/src/message.rb:9:in `publish'
src/sender.rb:6:in `<main>'
Sending message 9

Currently I am suppresing the $stdout when creating a new Stomp::Client instance like:

def self.suppress_output
  original_stdout = $stdout.clone
  $stdout.reopen File.new("/dev/null", "w")
  yield
ensure
  $stdout.reopen original_stdout
end

client = suppress_output { Stomp::Client.new(configuration) }

But I would like to know if that puts clause was intentional or was forgotten thereafter some debugging. From the commit blames I could not figure out. In case it should be removed I can open a PR removing it.

Thanks!

gmallard commented 4 years ago

Hi - I will certainly consider a PR for this.

However, please make suppression of the stacktrace optional, perhaps triggered by an environment variable.

Regards, Guy