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

Automatically reload REST server when file changes are detected #4299

Merged
merged 2 commits into from
Nov 2, 2022

Conversation

yifanmai
Copy link
Contributor

@yifanmai yifanmai commented Nov 1, 2022

Reasons for making this change

The REST server will automatically reload when file changes are detected when the service is started in development mode i.e. ./codalab_service.py start -bd. This eliminates the need to restart the REST server manually.

Related issues

Fixes #1182
Fixes #4199

Checklist

  • I've added a screenshot of the changes, if this is a frontend change
  • I've added and/or updated tests, if this is a backend change
  • I've run the pre-commit.sh script
  • I've updated docs, if needed

Copy link
Collaborator

@percyliang percyliang left a comment

Choose a reason for hiding this comment

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

I remember that the reason we didn't activate this was that for the bundle manager, you would still have to manually restart. But I guess we can try to do autorestart for that too?

Are there any downsides of doing this?

@yifanmai
Copy link
Contributor Author

yifanmai commented Nov 2, 2022

Yes, the bundle manager still needs to be manually restarted; the updated docs does mention this.

The main disadvantage that when there's an error on worker startup (i.e. a Python exception when importing the modules, caused by a bug in the code), gunicorn shuts down entirely. gunicorn restarts automatically when the bug is fixed. This can be confusing for the developer because the website will appear to stop working, and they will have to look at Docker logs to find the exception. Other frameworks (i.e. Django, Rails, Play) keep the server running and return the exception in the browser instead. This seems to be an inherent limitation of gunicorn.

The other options I tried were:

  • Setting reloader=True in bottle.run This reloads the gunicorn worker, but the code changes don't show for some reason.
  • Setting --reload on the gunicorn command line - The code changes show up, but an error on worker startup causes gunicorn to shutdown permanently, which means the developer has to manually restart the server; in contrast, --watch restarts the server automatically after the error is fixed.

The other disadvantage is that restarting the REST server causes it to lose state (e.g. in-memory global variables, persistent connections), but it is better for the REST server to be stateless anyway.

@yifanmai yifanmai merged commit c5fbe64 into master Nov 2, 2022
@yifanmai yifanmai deleted the yifanmai/4199-watch branch November 2, 2022 16:42
@leilenah leilenah mentioned this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants