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

Can we talk about / document threading semantics / requirements in PsychicHttp? #99

Open
egnor opened this issue Jun 17, 2024 · 0 comments

Comments

@egnor
Copy link

egnor commented Jun 17, 2024

I think everyone here knows that ESPAsyncWebServer (or at least its origin fork) is a disaster in terms of thread safety. PsychicHttp is reported to be much better, which is great! But it's important for users to understand threading semantics to be able to write safe code using it...

The README has similar notes as ESPAsyncWebServer does, without clarifying too much: "PsychicHttp is a fully asynchronous server and as such does not run on the loop thread. You should not use yield or delay or any function that uses them inside the callbacks."

It would be good (necessary, even) to know the following

  • Q: What is the thread context user callbacks are invoked on?
    • I think: the HTTP server thread, which means if that thread touches any of the same data loop() does, it MUST USE SYNCHRONIZATION, which basically nobody is doing?
  • Q: What threads can methods on various PsychicHttp type objects be called FROM?
    • The PsychicHttpServer object should ONLY be accessed from the setup() / loop() thread??
      • What if you want to access it from a request handler?? What's safe and what's not?
    • The PsychicRequest object should ONLY be accessed from the request handler
    • Similarly with PsychicWebSocketClient, ONLY access it from the event handler
    • But you can save the socket (an int) somewhere, and use getClient() later
      • where is it safe to call getClient() from??
      • how long is it safe to use the PsychicWebSocketClient you get back from that??
  • Q: What happens if you DO delay, or yield, or do long-running computation in a callback?
  • Q: What happens if you're sending lots of data, and the receiver is being slow (or goes offline entirely)?
    • Does this just stuff up the server thread indefinitely until some timeout?
  • Q: What happens if a client dribbles out the request headers and stuff?
    • Again, does this just stuff up the server thread indefinitely?
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

1 participant