-
Notifications
You must be signed in to change notification settings - Fork 132
Find a way to kill blocking handler callbacks #3
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
Comments
Hi, I am getting some requests stuck when the server tries to close the connection here as SSL_Shutdown never returns. You think this is related to this issue or should I look at something else? Cheers! |
Hi, thank you for the feedback! I created this specific issue mainly to improve handling more than one connection in parallel. As every request is delegated to a user-written handler function and the server passes control to this function, the server may be blocked as all connections are dealt with consecutively. If you imagine a client sending a big request body, which is split over several TCP packets, and one of those packets does not arrive, the handler function will wait for it indefinitely and never return. This issue is about solving this by allowing the handler function to return with a flag or something that says: "This request hasn't been processed completely, call me later again". Your problems seems to be similar, but not related to actual request handling but to tearing down the SSL connection. This part of connection handling should also not block the whole server task, obviously. I did not experience this issue by myself, but I suppose it might be related to the But we could cover this in this issue too, as it's definitively a way to block the server during request handling (maybe even from client side), with an impact on all connections to the server. To make some progress on it: Could you already determine whether the problem really is the If the loop is causing trouble and |
Warning! My level of experience with C/C++ is very low.
From what i can tell, when this happens This happens when the request is originating from a native Java android app i 've put together from bits and pieces here and there (Also not a Java developer :) ). If the request comes from a browser or Postman, it works fine and the SSL teardown completes. So it is for sure that the client does something wrong and i should fix that, but as you agree as well, the server should handle that case. Edit: I just discovered, the SSL teardown completes and execution proceeds after the amount of time the client has set to connection KeepAlive. It was set to 15minutes and i never saw it proceed before.
As a workaround for my case i was thinking of implenting a 'watchdog' like method which would either completely restart the device, or perform a check in that specific While googling i came upon this (which i assume is the same or related openssl library with ESP32's) which states among others:
Does that imply that you shouldn't wait for the SSL_Shutdown return value? Not sure, further below the contradict that. Thanks for the quick reply & thanks for creating the only working & complete (as far as i know) https esp32 server library! |
You are right that the server should not wait for it indefinitely, but have a look at the description for a return value of
That's the reason for the loop I used in the code (the line you mentioned above): This code was only a first attempt, and it assumes the client to eventually send the I can have a look into this and try to provide a fix, but it may take me some days due to other activities. In the mean time, you should be fine by changing line 121 to Another important thing regarding keep-alive is that it may be bound to the TCP socket rather than the TLS connection on client side. This would mean that |
Removing the while loop and running In the meantime although I couldn't find what was wrong with my client not respecting the close notify request, i discovered that there was another issue with the keep-alive and the client not re-using the active connection. Thus opening new connections, reaching the server's max connections and then getting stuck till the oldest connection was successfully closed. Also consider making the server's keep-alive timeout configurable if there aren't any other issues with that i may not be aware of. Thanks for looking into this. There is no hurry for me for a fix, it is working fine as it is. Cheers! |
It's not available via API yet, but you might be looking for this constant.
Clients not reusing a connection or using a connection pool is an issue, but due to the limited resources of the ESP32, it's hard to allow for more parallel connections. Even for only two or three parallel connections, the SSL handshake might fail (the server will than refuse the connection attempt). However, you are able to configure the parallel connections by modifying the third (and optional) parameter of the |
…endless loop (see discussion in #3 for details)
I tried to implement the SSL shutdown timeout can be configured here, after that period of time the server will continue to tear down the SSL connection without the client having answered. |
I have updated and so far it looks like its working as it should. Thanks again! Kostas |
Currently, when the
HTTPSConnection
passes control to the request handler function, this will pass control of the server's task/thread to this handler function. If it does not return (e.g. due to a misbehaving loop running infinitely), the server gets stuck there, does not accept any new connections and also does not handle other ongoing connections anymore.There should be some possibility to revoke control from those handler tasks, or at least a way for them to pass control back to the
HTTPSConnection
, without finishing the request. Maybe one could introduce a return parameter to the callback function that can be set totrue
to state that the very same callback has to be called again later, e.g. when more data becomes available on the underlying SSL socket. It would be nice to find a comprehensive approach that handles this problem and websockets as well (see #2).The text was updated successfully, but these errors were encountered: