Skip to content

Commit

Permalink
Timeout when trying to connect to a non-existant fedmsg-relay.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Oct 1, 2012
1 parent d9db18e commit a5d70ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions fedmsg/config.py
Expand Up @@ -55,6 +55,7 @@
timeout=2,
print_config=False,
high_water_mark=0, # zero means no limit
zmq_linger=1000, # Wait one second before timing out on fedmsg-relay
active=False, # generally only true for fedmsg-logger
)

Expand Down Expand Up @@ -184,6 +185,13 @@ def build_parser(declared_args, doc, config=None, prog=None):
type=int,
default=config['high_water_mark'],
)
parser.add_argument(
'--linger',
dest='zmq_linger',
help="Number of milliseconds to wait before timing out connections.",
type=int,
default=config['zmq_linger'],
)

for args, kwargs in declared_args:
# Replace the hard-coded extra_args default with the config file value
Expand Down
8 changes: 7 additions & 1 deletion fedmsg/core.py
Expand Up @@ -99,6 +99,9 @@ def __init__(self, **config):
if config['high_water_mark']:
self.publisher.setsockopt(zmq.HWM, config['high_water_mark'])

if method == 'connect':
self.publisher.setsockopt(zmq.LINGER, config['zmq_linger'])

config['endpoints'][config['name']] = _listify(
config['endpoints'][config['name']])

Expand Down Expand Up @@ -266,7 +269,10 @@ def publish(self, topic=None, msg=None, modname=None):
if self.c.get('sign_messages', False):
msg = fedmsg.crypto.sign(msg, **self.c)

self.publisher.send_multipart([topic, fedmsg.encoding.dumps(msg)])
self.publisher.send_multipart(
[topic, fedmsg.encoding.dumps(msg)],
flags=zmq.NOBLOCK,
)

def tail_messages(self, endpoints, topic="", passive=False, **kw):
""" Tail messages on the bus.
Expand Down

0 comments on commit a5d70ba

Please sign in to comment.