-
Notifications
You must be signed in to change notification settings - Fork 139
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
Long time responding #147
Comments
Hmm, that seems strange. Will you please enable debug logging to help me understand what is going on? Flask-CORS doesn't do much work, so I would be surprised if it was slowing down requests substantially. Are they eventually being returned successfully? If not, it is possible the browser is rejecting them, and there are information error messages in the console. |
I followed console it printed these :
Actually I dont know what is the reason of this problem. For example, the request shows pending the request after ajax start. It is pending until I call the ajax url from another chrome tab. After I call the ajax url from another chrome tab the ajax respond successfully. |
Looks like CORS finished. What is in the browser's console? Or the HTTP request log? It appears that the request being made is not actually a cross origin request, otherwise the browser would automatically send an Origin header. If you open the network request tab in chrome, you can inspect requests. |
Closing this issue for now, let me know if you have more information to help me understand what is going on here. |
I'm seeing a similar issue with a python REST API that I'm writing. The front end is angular 1.2.28. Often times requests hang for 20 seconds or more before returning. Here is the python code to set up the API:
The behavior doesn't seem 100% consistent but it happens much less often when I have the Chrome debugger console open for some reason. When it's closed it happens with more regularity (though still not all the time). If I remove Flask-CORS from the equation and start Chrome with CORS disabled using the
command line arguments, everything works fine, debugger console or not. All this behavior is consistent with Chrome on MacOS and Windows. Shown below is the Chrome debugger console window for sample request that took almost 1.5 minutes to respond. Here are the Flask-CORS and Werkzeug logs for that same request:
As you can see, nothing appears in the Werkzeug or Flask-Cors logs until right before the request comes back to the browser. Only 3 ms pass between when Flask-Cors gets the request and when werkzeug sends the response back. It's like the browser request isn't even making it to the server, but I can't figure out why removing Flask-Cors fixes it. Any ideas? |
Just a little more info. Refreshing the page and using the back buttons seems to create the issue more consistently. Also, this might be a Chrome issue. It doesn't seem to happen on Firefox or Safari on MacOS. |
FYI, it appears as though it is related to a thread setting in Flask. |
Wow, that is very very interesting. I'll take a closer look to try to understand what is going on here. Since this is somehow tickled when there is only one thread, it feels like it must be related to the usage of thread locals (current_app and request). |
https://github.com/LucaPaterlini/ajax_flask |
Luca, do you understand the cause of the issue? If so, please elaborate or make a pull request. I haven't yet dug into this, my plan was to first enable logging and add more verbose logging to see where things seem to stall. Thanks for the example! |
127.0.0.1 - - [10/Feb/2017 20:19:27] "GET /user HTTP/1.1" 200 -Exception happened during processing of request from ('127.0.0.1', 37550) This error appears when I've launched the page for the 5th time in a row, the previous 4 got data in milliseconds. I'm starting to fear that there is a race condition inside the code. |
@LucaPaterlini Can you provide more information in terms of OS and python version? I can't seem to replicate this behavior. As for your code, opening the same file from multiple threads, as your code does, looks suspect and may be an issue. |
Python 2.7.12 The issue appears in the demo I've shown before. app.run(debug=False,threaded=True) |
@LucaPaterlini what version of chrome was this in btw? |
I don't think chrome is involved in a python program that runs a terminal, above all |
@LucaPaterlini the reason I think Chrome may be involved is that the other reporter specifically mentioned that it only happened in chrome, and did not happen in Firefox. Luca, can you replicate this via CURL? A working demo repository that I could see the failed request in would be VERY helpful. Cheers, |
I've tested as well and I confirm that I've found the only browser that
presents those issue.
Now I'm going to recognize how lucky I am in getting into specific bugs.
p.s. should I could be included into the contributor list due to my lucky?
2017-03-03 0:04 GMT+01:00 Cory Dolphin <notifications@github.com>:
… @LucaPaterlini <https://github.com/LucaPaterlini> the reason I think
Chrome may be involved is that the other reporter specifically mentioned
that it only happened in chrome, and did not happen in Firefox.
Luca, can you replicate this via CURL? A working demo repository that I
could see the failed request in would be VERY helpful.
Cheers,
Cory
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#147 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC2ZfLLH2O6WcJtM-VkLO-JLj-HcKkYUks5rh0sLgaJpZM4H-3sz>
.
|
Haha :-) Lucky or unlucky, it is hard to tell! |
I'm going to close this issue until there is a reproducible case. If anyone has more information, I'd love to hear more! |
I all, thanks for investigating like me :) For your information, I experienced the problem in "Chromium Version 56.0.2924.76 built on Debian 9.0, running on Debian 9.0 (64-bit)" or in Chrome 56 under macOS. Running my application with I think this is equivalent to I do not have a reproductible case with Curl. I could not find how to debug more, either on the Flask side which displays logs after the hanging, or on the Chrome/Chromium side, which displays the request headers after the response is received. I would like to see the |
Just FYI, I still see the same problem: I'm using Flask-Cors==3.0.3. Running Mac OS X 10.11.6, Python 3.5.2. I experience this problem in Chrome (version 60.0.3112.113) with XHR requests. Safari and Firefox don't exhibit the problem. Curl doesn't exhibit any hanging or slowness (not doing XHR). The hanging/slowness seems to occur about 90% of the time, causing some very trivial requests to hang for 5 minutes or so. Running flask with |
@jrhite thanks for the report. I'm trying to run your project to see if I can reproduce it (and then investigate it properly). Looks like I am missing a 'repos.json' file? If you can update the instructions to make it possible for me to run that would be awesome. Thanks! |
Thanks for looking into this @corydolphin. Actually I don't have the project uploaded to GitHub, so you won't be able to see the project I'm working on (sorry about that). Let me see if I can quickly put together a barebones demo of this behavior in the next few days and get that uploaded for you (am traveling now). |
Ahh, my apologies -- I got confused by the reference above. That would be amazing, if you do that, I'll definitely look into it. Thanks for the help with this -- it looks like a bit of a funky problem. Will be a fun one to debug :) |
Hey, So sorry for the noise. This is almost definitely not an issue with flask-cors. This hanging/slowness problem with flask/chrome seems to be a pretty widespread problem and the theme pops up in google searches in lots of contexts not related to flask-cors. The Unfortunately for flask-cors, googling 'hanging chrome flask' and other similar variants pops up pallets/flask#2169 and #147 as the top 2 hits! ;-) It was just bad timing for me as I just started noticing the hanging problem pretty much around the same time I added flask-cors, and then I saw others with the same problem, so it seemed pretty conclusive. Still don't know the exact cause...it's intermittent and hard to reproduce reliably, but I can move along with the Anyway, if it helps at all, if someone asks about this again, you can point them to my simple demo cors-test. Just comment/uncomment line 9 of the cors-test.py file and people should still see the app hanging intermittently when using chrome when flask is not running in |
Hit this same thing today. The issue is the way Chrome opens speculative connections to speed up subsequent requests. If the speculative connection is accepted by the server first it hangs the singly threaded server. Nothing to do with flask-cors. I wrote up what I found here. |
@jeiting Thanks for the follow up and write up! |
I was having the same problem and setting up threaded = True resolved the issue. Couldn't find out the cause but Flask hangs for a brief time before even hitting the server. I have been seeing this issue often. |
On ajax cross domain request flask respond after a long time . For example 10 seconds.
If I call url from browser it respond fastly, but with cors and on ajax request flask wait a long time.
I'm working on localhost.
The text was updated successfully, but these errors were encountered: