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

Cls issue 70 #101

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion nsq/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _start_read(self):
def _socket_close(self):
self.state = 'DISCONNECTED'
self.trigger('close', conn=self)

def close(self):
self.stream.close()

Expand Down Expand Up @@ -276,6 +276,16 @@ def send_rdy(self, value):
self.rdy = value
return True

def send_cls(self):
try:
self.send(nsq.cls())
except Exception, e:
self.close()
self.trigger('error', conn=self,
error=nsq.SendError('failed to send CLS'))
return False
return True

def _on_connect(self, **kwargs):
identify_data = {
'short_id': self.short_hostname,
Expand Down
14 changes: 14 additions & 0 deletions nsq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ def heartbeat(self, conn):
:param conn: the :class:`nsq.AsyncConn` over which the heartbeat was received
"""
pass

def close(self):
"""
Closes all connections stops all periodic callbacks
"""

for conn in self.conns.values():
try:
conn.send_cls()
except Exception, e:
logger.warning('[%s:%s] error sending CLS, closing',
conn.id, self.name)
conn.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add accounting for outstanding messages and wait until they're all responded to before we actually close the connection (after sending CLS)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this outstanding message accounting an issue for just Writers? Readers? Or both?

Also, is an outstanding count good enough, or do individual messages need to be tracked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the reader - a count is sufficient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about I boost this up to the conn level, where there's already a counter for in-flight messages?

Also, what do you think about tacking on a time-out where one gives up on any outstanding messages and just sends the CLS?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM


2 changes: 2 additions & 0 deletions nsq/nsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def touch(id):
def nop():
return _command('NOP', None)

def cls():
return _command('CLS', None)

def pub(topic, data):
return _command('PUB', data, topic)
Expand Down
6 changes: 3 additions & 3 deletions nsq/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ def close(self):
"""
Closes all connections stops all periodic callbacks
"""
for conn in self.conns.values():
conn.close()

self.redist_periodic.stop()
self.query_periodic.stop()

super(Reader, self).close()


def set_message_handler(self, message_handler):
"""
Expand Down