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

Safety #294

Merged
merged 4 commits into from
Apr 9, 2018
Merged

Safety #294

merged 4 commits into from
Apr 9, 2018

Conversation

Peque
Copy link
Member

@Peque Peque commented Apr 6, 2018

Fixes #287.

Not really proud about the final result, but should definitely be a step forward...

@Peque Peque added this to the 0.7.0 milestone Apr 6, 2018
@Peque Peque self-assigned this Apr 6, 2018
@Peque Peque requested a review from ocaballeror April 6, 2018 12:54
@codecov
Copy link

codecov bot commented Apr 6, 2018

Codecov Report

Merging #294 into master will increase coverage by 0.14%.
The diff coverage is 96.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #294      +/-   ##
==========================================
+ Coverage    99.1%   99.24%   +0.14%     
==========================================
  Files          26       26              
  Lines        3557     3588      +31     
  Branches      258      257       -1     
==========================================
+ Hits         3525     3561      +36     
+ Misses         19       15       -4     
+ Partials       13       12       -1
Impacted Files Coverage Δ
osbrain/tests/test_nameserver.py 98.11% <100%> (ø) ⬆️
osbrain/tests/test_agent.py 100% <100%> (ø) ⬆️
osbrain/agent.py 98.14% <95.55%> (+0.43%) ⬆️
osbrain/tests/test_bugs.py 100% <0%> (+16.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cffe79b...049f7d9. Read the comment docs.

osbrain/agent.py Outdated
"""
Close a socket given its alias and clear its entry from the
`Agent.socket` dictionary.
"""
if linger is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change the linger thing?

I mean, this is what I had in mind a while ago when I was looking at #256, but I don't see how adding linger as a parameter can help this PR at all. (this comment also applies to the changes in .close_all())

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, don't you think this would need new tests? Maybe we should open a new issue so we don't forget when we come back to this project in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned in my other comment it is to set linger to zero when killing (i.e.: killing should be fast).

This would definitely need more tests. I do not think we need to create a new issue, as there is #255 already.

Anyway I think you are right. I will either add some tests or undo that linger change (and remove the _die() method, which would make little sense then.

osbrain/agent.py Outdated
else:
self._die()

def _die(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

The _die method seems overly complicated to me. I think it just adds an unnecessary amount of code. Go on with whichever solution you like best, but consider this implementation as well:

def run(self):
    ...
    if self._kill_now:
        self.kill()

def kill(self):
    self.stop_all_timers()
    if self._running:
        self._context.term()
    else:
        self.close_all()
        self._pyroDaemon.shutdown()

# And delete the `die` method.

If you end up keeping yours, maybe consider renaming _kill_now to _die_now

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree with you. I forgot to upload one more change though, which perhaps justifies that division.

When cleanly shutting down, we use the default/configured linger, but when killing the agent we do not want to wait, so we want to close all sockets without waiting. In that case I would not add a parameter to the kill() method, as killing should always mean "right now". Hence the reason to create a new internal method.

I just pushed a fixup with that change only. What you think?

I can rename the _kill_now variable as you say. Makes more sense anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you mean. I don't want to complain too much about this since it makes sense for the most part, so check out my latest revision and then we can move on with this.

Copy link
Contributor

@ocaballeror ocaballeror left a comment

Choose a reason for hiding this comment

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

Also rename the attribute we were talking about before, if you agree.

osbrain/agent.py Outdated

def _die(self):
def _die(self, linger):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really necessary, but I think it looks better 😁

Consider changing the method signature to:

def _die(self, linger=None)

And then change the end of .run() to self._die()

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed signature and renamed attribute.

@ocaballeror
Copy link
Contributor

Maybe merge #296 first? That way we can merge this with the tests passing.

@Peque
Copy link
Member Author

Peque commented Apr 9, 2018

@ocaballeror Rebased, squashed and added socket close with linger tests.

@Peque
Copy link
Member Author

Peque commented Apr 9, 2018

Also pushed a new commit to fix: https://travis-ci.org/opensistemas-hub/osbrain/jobs/364043140

I looked for other possible occurrences in our test suite and that seems to be the last one.

@Peque Peque merged commit 049f7d9 into opensistemas-hub:master Apr 9, 2018
@Peque Peque deleted the safety branch April 9, 2018 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants