http res.on('close') never called for some GET requests #4644
Replies: 1 comment
-
Posted at 2015-03-11 by @gfwilliams Can you try requesting a bigger file? With 2 characters I guess it's possible that the connection would have already closed by the time the main function was called. I know I deal with that for the data handler, but maybe not the To work around it, you could do:
Posted at 2015-03-11 by net-tobi Hi Gordon, with a bigger file the close handler is getting called and it works as expected. Best, Tobias Posted at 2015-03-11 by @gfwilliams Ok, thanks - I'll make a bug for it. The workaround I suggested should fix it for now though Posted at 2015-03-11 by net-tobi Thank you! Posted at 2015-03-11 by @gfwilliams Posted at 2015-03-11 by @gfwilliams Just to add that:
Should also work for you - and might be better. Posted at 2015-03-11 by net-tobi Both workarounds don't work for me. The response is closed too fast, so the on-handlers for "close" and "data" are not getting called, because it is too late. Posted at 2015-03-11 by @gfwilliams That's odd - the data handler should work. What should happen in that case is that when the Posted at 2015-03-12 by net-tobi It seems to be a timing problem of the asynchronous calls. I experienced situations where it worked with the same function and the same data without any changes being made. But for now it is not working for me. Posted at 2015-03-20 by net-tobi Do you have another idea how I can realize a workaround since both suggestions doesn't work for me? Posted at 2015-03-20 by @gfwilliams Ok, I just tried what was basically your code, on a WIZnet device (with the current firmware), connecting to an Apache server:
Result is:
And it works every time. Any thoughts about what could be different? What happens when you use Espruino with Apache, rather than Express? Maybe Express is somehow doing something different? As far as workarounds, if you control the server and we can't figure this our, why not just send a few more bytes? Posted at 2015-03-20 by net-tobi Thank you for your response again. I'll try that out on the weekend with Apache and try to deeper analyze the problem in my special case. Currently my workaround for the problem is to set a timeout before I send the request and call the callback if nothing is getting returned. I'll provide you with updates soon. Posted at 2015-03-20 by @gfwilliams Are you using WIZnet, or some other module for accessing the net? I guess that could have some affect (although I tried on Linux as well). Also I wonder whether it is because there is a lot of code being called after Posted at 2015-03-20 by net-tobi I am using the CC3000 module. I'll try it with setTimeout as well at the weekend Posted at 2015-03-22 by net-tobi I spent some time to analyze the problem... It seems to be a problem with my CC3000, because sometimes the same code worked and sometimes not... I get such errors very often:
and
Maybe it is a problem with the firmware. Do you know exactly which USB cable I need for an update? What is the state of the ESP8266 problems? Maybe I can use that, if these are solved. Posted at 2015-03-23 by net-tobi I found a way to update my CC3000, I now have less error messages, but the problem with the close Handler persists. Posted at 2015-03-23 by @gfwilliams Yes, the CC3000 isn't desperately reliable. When I get a moment I'll see if I can try a similar 2-character request with it - but honestly it wouldn't surprise me if it was some problem with the module itself. I seem to recall that if you tried to receive data on a closed socket it'd just crash, so it's possible that there is no way to get the small response out of it. Is this is for your uni project? Can you not just modify your server slightly to either send more data or to hold the connection open for a few more ms after sending? The ESP8266 support is getting there, but it still needs some work as different versions of firmware need slightly different commands. Did you try connecting to an Apache server? Posted at 2015-03-23 by net-tobi Thanks gordon. Yes it is for the project I explained to you via email. Sure I can send more data from the server side, that's a workaround which is ok for the moment, but the final solution shall be able to process the data in a correct way (wether it is less or more data). I performed some tests with Apache which came to the same result. I have no problem switching to the ESP8266 when it is working in a proper way with the latest firmware. In this project I use WLAN for the presentation. The final version of the system shall use GPRS which I will adapt as soon it is officially supported. Best, Tobias Posted at 2015-05-01 by @gfwilliams Just to add, I recently made a change (it'll auto-build to http://www.espruino.com/binaries/git/commits/5ae24206fb924569f14265fa57372132356a7a75 soon, or will be in 1v78) that may well fix the problem you're having with close not being called. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-03-11 by net-tobi
Dear community,
sorry for writing again about problems I experienced with Espruino. I used the latest build of 1.75.
I experienced that the "close" event of the http response is not raised for the same get request. No matter how often I try. On the other side I am using the Express JS framework. With other HTTP clients it works well.
The response looks ok:
How can I handle such problems with the http class of Espruino? What is the problem, that the "close"-event handler is not getting called?
Best,
Tobias
Beta Was this translation helpful? Give feedback.
All reactions