I deployed my rails project on heroku but I am facing timeout error on heroku. I am using puma server on heroku. My project is about scraping web data using URL. I also tried webrick & unicorn server. Can anybody suggest me the solution for this problem?
Your question is lacking information about what is causing the Timeout error. As you are fetching data from other web pages, it's likely the timeout is caused by a not responding HTTP URL.
In this case, the web server you are using may be irrelevant. In fact, Heroku imposes a request timeout of 30 seconds. If your app doesn't return a response within 30 seconds, the request is terminated by Heroku. It doesn't really matter which web server you are using.
In order to solve this problem you have to
set a timeout in your code (you can use the Timeout library) to make sure that no external HTTP request takes more than a certain period of time, which must be lower than the Heroku timeout.
you may also want to move lon-running tasks away from the context of a request into async jobs that are not subject to the request timeout in Heroku. However, in order to do that you will require a background job system such as Sidekiq or Resque.
Related
I have a django channels project. I'm currently using the
ASGI/Channels version 2.1.7 development server
When I start up the server, and connect to it with a browser, the HTTP requests start getting served right away, and the HTML page loads in the browser. As soon as the page loads, it tries to establish a websocket connection, which fails.
I'm using reconnecting-websocket library, so it keeps trying, and failing. I can see it failing because there are messages in the firefox console that say the connection attempt failed. Refreshing the page doesn't help. After about 30-45 seconds, it starts working. At that point, as long as I keep the development server running, I have zero issues with my websockets - they always connect right away when I load a page that uses them.
The problem doesn't always appear (sometimes it works right away), but when it doesn't, it's always the first 30-45 seconds after starting the development server. It's very annoying to have to wait 30-45 seconds during development every time I need to restart the dev server.
A tcpdump on the server shows websocket requests coming in with a proper destination port, but getting a TCP RST. The failed connection attempts don't show up in the development server logs at all (the ones printed to the screen). It almost seems like Linux is dropping the requests because the socket is busy or something. It's strange though that HTTP requests don't get dropped, but websocket requests do, even though both use the same port.
Anyone have any ideas? Anyone come across this? Any extra debugging I can enable, either on Linux, or on the dev server?
Edit: Using nginx and daphne for deployment, I have no problems. As soon as systemd starts up both nginx and daphne, which only takes about 3 seconds on my raspberry pi, I can load the page, and the web sockets connect perfectly. Only the dev server has issues.
Recently some users have been experiencing this error. This error doesn't appear until the user is in the application for a bit (Ranged from a couple minutes to hour and a half).
When this issue first came up, I modified the application.cfm file which contains the timeout variables. This helped one user, but now more are experiencing the same error. Below is the modified code, I exended the timeout to 200 minutes.
<CFAPPLICATION
NAME="MyApplication"
SESSIONMANAGEMENT="Yes"
sessiontimeout="#CreateTimeSpan(0,0,200,0)#"
applicationtimeout="#CreateTimeSpan(0,0,200,0)#">
My question: Users are still experiencing this timeout error within 5 minutes, after I set the timeout to 200 minutes. Can there be a variable or something that is set on the CF Admin side which overrides my timeout span? If there is not, I will need to research into this more. Any suggestions or comments are helpful, thanks.
You definitely need more info from the hosting provider. Common issues include:
They are load balancing and not using sticky sessions. So the user will have to login and create a session on each server that is part of the loadbalanced cluster.
They have a proxy or webserver in front of the ColdFusion server with configuration that alters the response from the ColdFusion server.
They have settings in the CFAdmin console that limit the application settings, as per the comments provided by TRose and Chris.
So the concern is timing out: IIS, Apache, and TomCat web services can timeout as well. For example if Apache is set to timeout in 300 seconds but Coldfusion is set to timeout in 350 the web service will always trigger beforehand (it won't matter what you do in Coldfusion Admin or Cfsettings because the web server supersedes it).
So web server timeout implementations could front run your Coldfusion to timeouts.
I have a django web app running via gunicorn and nginx is serving as a reverse proxy.
The web app provides few API calls. One of the API call (let's say GET /users) is giving me a Connection timed out error. All other HTTP calls work fine always.
If i restart the Django/gunicorn process, GET /users works fine for a couple of hours and then starts giving same problem again.
GET /users is simply parsing query params and pushing some data into rabbitmq. It's not the issue with rabbitmq connection/channel, that i am positive.
Anyone has any idea what could be wrong?
I have tried all available solutions on stackoverflow (including modifying proxy* headers in nginx, changing gunicorn timing and what not.)
How can I set a request timeout using Python Flask? I'm trying to compare Flask to some other framework and need to configure the timeouts to be equivalent.
Thanks!
As Martijn Pieters said in their comment on the question, this isn't something you want to do because the Flask development server isn't a good choice for production. It would be better to run your flask application on a server like Gunicorn and set the timeout there instead.
But to answer the question anyway, Flask.run has an options parameter allowing you to pass options through to the underlying Werkzeug server:
run(host=None, port=None, debug=None, load_dotenv=True, **options)
The relevant werkzeug method in turn has a request_handler parameter allowing you to specify what request handler is to be used:
werkzeug.serving.run_simple(hostname,
port,
application,
use_reloader=False,
use_debugger=False,
use_evalex=True,
extra_files=None,
reloader_interval=1,
reloader_type='auto',
threaded=False,
processes=1,
request_handler=None,
static_files=None,
passthrough_errors=False,
ssl_context=None
)
This is your hook for supplying a request handler object that implements the timeout policy you want (a subject explored in this question: How to implement Timeout in BaseHTTPServer.BaseHTTPRequestHandler Python).
WSGI server
WSGI is the protocol, a facade separating your code from the actual web server which runs it.
In the flask, you only create the logic of the server. On run, your Flask application is served by the WSGI server. The most common is uWSGI ( & nGinx proxy to the secure border between the outer world and your server). But you can use whichever WSGI server suits you best without need to change your code (nichol.as/benchmark-of-python-web-servers)*.
Flask itself ships only with the Development WSGI flask server. It means the server uses a lot of features to help the developer debug their application. These features make the server very slow. So when you do a benchmark of your app on the Development WSGI flask server, results have no value for you.
On the other hand, specialized production-ready WSGI servers (including uWSGI) are well optimized, tested and production-proven. Most of the features are usually turned off by default and allow you to fine-tune these powerful beasts for your application.
Deployment tutorials:
flask+wsgi: https://flask.palletsprojects.com/en/1.1.x/tutorial/deploy/
flask+uwsgi+nginx:
http://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/
Timeout
Now when I explained the context, back to your original question. I would set requests timeout in your:
test client :
import requests
requests.get('https://api.myapp.com', timeout=3)
<Response [200]>
nGinx proxy cofing:
http
{
server
{
…
location /
{
…
proxy_read_timeout 120s;
…
}
}
}
If the question is related to the Flask timeout while waiting for the completion of the browser data request after a TCP socket connection is set-up by the browser and accepted by Flask (i.e., werkzeug, where each line sent by the browser resets the timer), a trivial solution would be to add this before app.run(...):
import socket
socket.setdefaulttimeout(10) # seconds
Setting it once at the beginning of the program affects all new socket connections.
A timed out request generates the BaseHTTPRequestHandler error Request timed out: TimeoutError('timed out').
This configuration does not appear to control the time Flask takes to process a valid request, which should be implemented inside the function decorated with #app.route(...).
I have a web service that has been running on CF 8 for awhile now without issues. We've recently moved to CF10, and this web service no longer works. I've already tried switching the Axis setting to 1, it's still tossing errors. Has anyone else encountered this, or have an ideas on what else to look for here?
Process:
CF Server sends a web service request to App Server.
App Server processes request, generates another web service back to CF Server with SOAP data pushes, then replies back to the step 1 originating request with a boolean response on how its own web service request went.
CF Server Errors:
The web service operation caused an invocation exception.The root cause was that: ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error.
Cannot perform web service invocation [Method Name]. The fault returned when invoking the web service operation is: java.lang.NoClassDefFoundError: org/apache/james/mime4j/MimeException
App Server Error Logs:
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
SEVERE: SAAJ0009: Message send failed
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
Caused by: java.io.IOException: Error writing to server
I've gone as far as modifying the App Server configuration to have it's web service request push out to the CF 8 server for processing, while still replying back to the originating request from the CF 10 server. This worked fine. It's definitely something with the requests or my CF 10 web service config.
I can't post any of the code examples unfortunately.
24 Sept 13 Update
I've tried various combinations of v1 and v2 in the CF admin, with wsdl and wsdl2, and the application.cfc setup. The app that is interacting with this service has given me the ability to modify a variety of parameters for soap versioning and some internal items. I can get the two services to talk with a bare bones connection of give me your soap and I'll toss a YES back. Whenever I try to use the full request it seems to never actually hit my web service, and gets stopped somewhere by CF. I see no logging on it other than in the web service log.
I found the solution to my problem. The ColdFusion connector was causing the fault. After installing ColdFusion 10 and patching, I had run the wsconfig to rebuild the connector. I had either done this incorrectly, or for some reason it didn't take. I ran it this morning, removed the connector, re-added it.... everything working fine now. Very frustrating.