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
Client and server behavior at the same time #845
Comments
For the client and server threads, there can be no overlapping static variable definitions otherwise the 2 threads could get confused here. lwip_select() returns EBUSY after 256 calls if one of the file descriptors passed in is watched, but not released for some reason. 256 seconds is 4 1/4 minutes which ties up with the run time that you are seeing. I assume that it is the client thread that is failing, not the server thread. In the client, are you creating a new (coap_session_t) session for each request, or are you using the same session for each new request. You should be doing the latter (i.e. create the session once and use that session for each new coap_send()). |
Hi mrdeep! I will check what you've told me about the time and see if it matches. Any other clue on what could be happening will be appreciated. |
Hi again! |
Could this be related with this portion of code? (taken from
The esp32 arduino framework uses COAP_CONSTRAINED_STACK = 1 as far I could see. I've seen that you push new commits on the weekend related to this. |
The new commits pushed over the weekend were rebasing some PRs on the latest develop code which were resolving merge conficts from the latest code updates on hte develop branch. Yes, the esp-idf code does have I will try tomorrow setting up a code test for what you are trying to do with the edp-idf code. It is possible though that there is an issue with an esp-idf network driver that this not releasing a socket usage counter. FYI, the section of lwip_select() from esp-idf is
where |
Hi! |
I am not able to reproduce your issue with a standalone esp-idf emulated server and many requests coming in to that server. Is it possible to get the source code for the 2 examples you are running? |
Hi mrdeep1! Thanks for your time! Actually I have both, server and client, converted into c++ classes. In the problem description I linked both examples I used as references. Actually I have both, server and client, converted into c++ classes. But, converting to c again, I have this: server:
client:
|
Using your code - which needed a couple of changes to make it compile - has been running for 1.5 hrs with a client request every second now without failure on a QEMU emulated system (using OpenCores driver). So it does look like it is an issue with whatever network driver you are using. |
OK. I will look into it. |
I have managed to reproduce something - digging into it at present. |
The issue is down to Can you please try updating
and let me know how it goes. |
mmm. I am fu#$%#$% with that. Actually because I have the Arduino framework with the precompiled espidf (yeah, I know it sucks, I haven't chosen that). Certainly it is compiled without those lines and it is using that crappy stub. |
esp-idf extra components PR 61 has been raised to fix this. My test code has now looped 17,500 times with no error. |
espressif/idf-extra-components#61 has now been merged into the master branch, and hence generally available. @fbucafusco Please close this issue if you are happy with the solution. |
@fbucafusco Please free to re-open this issue if there still is a problem. |
Hi again! So, I reviewed the mutex implementation, and I realized that the mutex is a unique object (is static within BTW. If I shut down the server, the system's timing is correct. Thanks in advance for the help. |
The mutex in
which could be on the stack, but may cause stack overrun issues. I appreciate it is not easy for you to change the build of libcoap, so not sure how to move forward here. A possibility is to reduce the wait time on the |
I will increase the stack just in case. I haven't tried that yesterday. |
I don't think that increasing the stack size will fix this issue. Reducing the delay time to 100ms on the Otherwise. changing |
@fbucafusco See PR #981 for a proper fix here. |
Hi! |
Hi. I did some more tests and reducing the time, as I stated, helped but not solved the issue fully. Sometimes weird things happen. |
This PR #981 has now been merged into idf-extra-components - see espressif/idf-extra-components#215 |
@fbucafusco Can this be closed now? |
Why is it even necessary to have two coap contexts? Why not reuse the same socket for both client and server? |
@mkschreder There is no need to have 2 coap contexts if a client and server are running at the same time (which is what is happening when the standard libcoap coap-server is running as a proxy server forwarding on requests and forwarding back responses. BUT, as libcoap is not currently multi-thread-safe, both the client and server logic need to be running on the same thread if they are to share a common coap context. Then there are coap sessions (acting as a coap endpoint) which actually open a socket and either connects to a remote server, or listens for information coming from a client. It is possible to have multiple coap sessions per coap context. In theory, a single coap session can act as both a server endpoint and a client endpoint (i.e. use the same socket), but this does not give you port to use flexibility (as both the server listening port and the source port of a client connecting to a remote server have to be the same). |
Hi! |
Thanks for the feedback and update. I will close this off now. |
Environment
Problem Description
I need my system to have a coap server and a client working at the same time.
I took code from both examples (from the ESP-IDF client and server ) without any sec layer.
Basically I created 2 tasks where each example is running, so the libcoap lib is working on two different libcoap contexts. So I have 2
coap_io_process
calls (on different pbjects of course). The client demo is sending a message each second, while the server is waiting for remote requests. Each server and client uses a different port.I am having an issue where everything goes ok, but after a random running time (in general after 5 or 10 minutes) the
coap_io_process
function starts returning EBUSY. I went deep intocoap_io_process
and it seems that EBUSY comes fromlwip_select
function and I think is related to some mutual exclusion mechanism, but I don't really understand why it is happening this.Not so sure if that is a bug or it's me doing things wrong.
If you have some idea of what could be happening to me, or something that you want me to try, I will appreciate.
The text was updated successfully, but these errors were encountered: