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

is there any right way to interrupt a started server? #68

Closed
polymorphm opened this issue Dec 12, 2017 · 7 comments
Closed

is there any right way to interrupt a started server? #68

polymorphm opened this issue Dec 12, 2017 · 7 comments
Labels
question StackOverflow

Comments

@polymorphm
Copy link
Contributor

polymorphm commented Dec 12, 2017

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository

  • Do you want to request a feature or report a bug?

bug? or may be it is a feature request?... no.. I think it is a bug (I don't know)

  • What is the current behavior?

the method server.interrupt [of class cherrot.Server] seems like useless.

I can not invoke the method server._set_interrupt() [the property server.interrupt] from the same thread where I just invoked server.start(), because the method server.start() is blocking the thread.

and I can not invoke server.interrupt() in another thread, because server._set_interrupt() invokes server.stop() inside himself. but server.stop() isn't threadsafe!

the method server.stop() isn't threadsafe -- because it has a race condition with the method server.start(). and there isn't a way how to wait for the moment when the method server.start() will pass his initialization (dangerous) point.

how can I use right way to interrupt a server?

I've found the way (the workaround?) like this:

### thread A ###
try:
    server.start()
except MyStopError:
    pass
finally:
    server.stop() # ---- will be invoked always after ``server.start()`` and always in the same thread
### thread B ###
server._interrupt = MyStopError() # ---- doesn't do anything except setting a flag

i.e I've tried to avoid using server._set_interrupt(), so I've got ability to invoke the method server.stop() inside the thread A after invoking the method server.start() in the same thread (the race condition wouldn't happen).

  • What is the expected behavior?

if the method server.start() an server.stop() would be use synchronization primitives -- it would NOT fix the problem(!) . because in this case the race contition with server.stop() will still happen at moment before starting the method server.start() (in detail: in thread B we can at random invoke stop() before invoking start(), so the stop() will not stop anything).

and of course -- I can not set server.ready = False in the thread B, because I still have race condition for this variable with the method server.start() invoked in the thread A. it is the real problem..

I think one of the way -- it is to split the method server.start() to two separated methods:

  • the first method for a start-initialization phase (not blocking method)
  • the second method for a serving phase (blocking method).

this separation will allow to know that you can correctly invoke the method server.stop() -- after the start-initialization phase is done.

thank you in advance!

@stale
Copy link

stale bot commented Feb 10, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale This thing has been ignored for too long label Feb 10, 2018
@webknjaz
Copy link
Member

I need to find time to dig into it.
@jaraco do you have any comments on this post?

@stale stale bot removed the stale This thing has been ignored for too long label Feb 10, 2018
@jaraco
Copy link
Member

jaraco commented Feb 11, 2018

I haven't experienced this issue, but the analysis seems sound.

@stale
Copy link

stale bot commented Apr 12, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale This thing has been ignored for too long label Apr 12, 2018
@stale stale bot closed this as completed Apr 19, 2018
@jaraco
Copy link
Member

jaraco commented May 22, 2018

@polymorphm Would you consider putting together a pull request implementing the approach you've outlined?

@polymorphm
Copy link
Contributor Author

I would be glad to make a pull request (in some days. at this weakend!).

but I'm afraid that the names of new-functions may turn out to be not very good :-) .

@webknjaz webknjaz reopened this May 26, 2018
@stale stale bot removed the stale This thing has been ignored for too long label May 26, 2018
@polymorphm
Copy link
Contributor Author

I've made pull #98 ..

it seems, I've to do pull's "Checklist" :-) ..

@webknjaz webknjaz added the question StackOverflow label Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question StackOverflow
Projects
None yet
Development

No branches or pull requests

3 participants