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

ERR_TIMED_OUT on multi requests #7

Open
dizcza opened this issue Jun 2, 2023 · 4 comments
Open

ERR_TIMED_OUT on multi requests #7

dizcza opened this issue Jun 2, 2023 · 4 comments

Comments

@dizcza
Copy link

dizcza commented Jun 2, 2023

I'm using your tiny http server to serve firmware updates for my ESP32 boards.
I have ~10 such boards in total all requesting to download a file. HTTPS + auth mode. And as soon as they all start a request, the server is no longer reachable (even from my PC).

Also, I noticed that if any such request fails, the server is stalled and not recovered until reset.

Perhaps, threads + timeouts on error would help.

@dizcza
Copy link
Author

dizcza commented Jun 2, 2023

The connection is weak causing more errors on both sides: server and client.

@johann-petrak
Copy link
Owner

Hi - the reason why this module is called "tiny" is because it avoids all the complexity of serving many connections in parallel, keeping long/slow connections open etc.
If you need that please consider using a full-fledged server instead which supports all this.

My feeling would be to close this as WONTFIX, but I will leave it open for a while if anyone wants to contribute a small and easy fix if it exists, but this should definitely not become a reinvention of much bigger wheels :)

Heavy duty is probably best achieved by using e.g. flask with gunicorn.

@dizcza
Copy link
Author

dizcza commented Jun 2, 2023

I agree, feel free to close it as wontfix.

I've done some projects with flask and gunicorn and I'm also thinking about these tools but I'd rather pip install something ready to use :) I cannot believe that such a tool that graciously handles many parallel requests without crashing does not exist in python - I'm talking about HTTPS + auth server. But I cannot find anything! Perhaps you came across such tools?

@dizcza
Copy link
Author

dizcza commented Jun 2, 2023

All right, I've come up with the simplest file-sending server on flask + gunicorn. Posting it here for other users:

import os

from flask import Flask, send_file
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash

app = Flask(__name__)
auth = HTTPBasicAuth()

FIRMWARE_PATH = "firmware.bin"

users = {
    os.environ['ENV_OTA_SERVER_USER']: generate_password_hash(os.environ['ENV_OTA_SERVER_PASS'])
}


@app.route(f'/{FIRMWARE_PATH}')
@auth.login_required
def download_firmware():
    return send_file(FIRMWARE_PATH, as_attachment=False)


@auth.verify_password
def verify_password(username, password):
    if username in users and \
            check_password_hash(users.get(username), password):
        return username


if __name__ == '__main__':
    app.run(debug=False, port=8070, host="0.0.0.0")

The script servers only one predefined file. And I'm launching it with gunicorn like so:

gunicorn --certfile ca_cert.pem --keyfile ca_key.pem --worker-class gevent -b 0.0.0.0:8070 app:app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants