Can someone please explain why one uses this client.setReadTimeOut and client.setConnectTimeOut timeouts? I am using the same with my Jersey client. I have set a timeout of 5 secs for both connect and read. And for testing purpose I have put a thread sleep in my service for 6 secs. I get a timeout exception but after that my service resumes and gives response as normal. My requirement is to set a timeout for the service to respond and if it is passed it should come out and try again. Also I need to set number of attempts the client should try to connect. Please suggest
You client times out after 5 seconds not having heard back from the server and throws a timeout exception as designed. It has no idea whether the server started processing the call or will later on.
When you server wakes up from its sleep, it also has no idea the client timed out. You could check the status of the connection but it'd not be very reliable.
You client may catch the timeout exception and retry the call as many time as you wish. If your concern is about the same server call being executed more than once, then you have to implement you resource method to be idempotent.
Related
I hope who ever is reading this is doing well.
Here's a scenario that I'm wondering about: there's a global ClientConn that is being used for all grpc requests to a server. Then that server goes down. I was wondering if there's a way to wait for this server to go up with some timeout in order for the usage of grpc in this scenario to be more resilient to failures(either a transient failure or server goes down). I was thinking keep looping if the clientConn state is connecting or a transient failure and if a timeout occurs when the clientConn state was a transient failure then return an error since the server might be down.
I was wondering if this would work if there are multiple requests coming in the client side that would need this ClientConn so then multiple go routines would be running this loop. Would appreciate any other alternatives, suggestions, or advice.
When you call grpc.Dial to connect to a server and receive a grpc.ClientConn, it will automatically handle reconnections for you. When you call a method or request a stream, it will fail if it can't connect to the server or if there is an error processing the request.
You could retry a few times if the error indicates that it is due to the network. You can check the grpc status codes in here https://github.com/grpc/grpc-go/blob/master/codes/codes.go#L31 and extract them from the returned error using status.FromError: https://pkg.go.dev/google.golang.org/grpc/status#FromError
You also have the grpc.WaitForReady option (https://pkg.go.dev/google.golang.org/grpc#WaitForReady) which can be used to block the grpc call until the server is ready if it is in a transient failure. In that case, you don't need to retry, but you should probably add a timeout that cancels the context to have control over how long you stay blocked.
If you want to even avoid trying to call the server, you could use ClientConn.WaitForStateChange (which is experimental) to detect any state change and call ClientConn.GetState to determine in what state is the connection to know when it is safe to start calling the server again.
I've been using Sinatra with Rack for simulating external services when running integration tests, and would like to write a test for the case when the server is down. Is it possible to have Sinatra simulate a 'Connection Refused' error without entirely shutting down the server process?
So far I've tried:
Raising an exception
Immediately closing the stream, as illustrated here, before the method returns or anything:
post '/external_app' do
stream(:keep_open) do |out|
out.close
end
end
Thanks!
You are trying to test server down, the approach you've done still relies on the response of sinatra server.
you can set a very short connection timeout in your http client (any http client should be able to do that)
And then have something like a sleep method in your sinatra action block with x seconds that's greater than the max timeout you set.
But actually you may not need to make things that complicate, you can just throw an exception that your http client throw for connection timeout (and any other connection exceptions), and test to see if your application is able to catch and process the exception(s) accordingly.
I am writing a REST service where the result of a REST POST can take longer than the environments timeout settings for HTTP connections. Given that I can't change the timeout for my REST target url,
What can I do to to make a REST call pass properly? I thought about using an async controller, but that seems not to fix any timeout behavior.
The calling client should not have to handle any server error or try to re-execute the query, as it is just adding more stress to the server.
Cheers,
Kai
Assuming this is a connection read timeout and not a http keepalive timeout since there is only one query. One suggestion would be for the rest service to return intermittent status response every specified interval. If this is a tcp keepalive issue then it can be circumvented using configuration. If a socket read timeout is being set then thst can be increased as well.
My application environment is Tomcat 7.0, JDK 1.7. I am using Jersey for the REST API. One of our post type REST API request takes the processing more than 3 minutes, and it is just approx time, it can be more than 3 minutes. Then we send the response back to the client when our request processing is completed. but here request processing take 3 minutes so I got the request time out at the client side , and I do not get any response from the server , as I expected to success response
Request processing at server is like below:
Start the request
Insert details to db table [this process taking time in seconds]
Copying files to remote computer server [this process taking 3 minutes]
Update/active the files [this process taking time in seconds]
Send response to the client
End the request processing
All the above process must be in transaction , so we can not remove any of the above process,
We had already improve the best performance for Step 2 of the process , and it only happens, when we request with the more than 1 gb size file.
As of now for the temporary solution we had increase the timeout value which is configured in the Apache server.
Now I am looking for the solution of my issue, with any of the following approach:
Suggest me any development or implementation strategies which can resolve the my issue and it should be expected as described me?
How do I tackle the request time out issue?
Looking for the solution which notify the client from the server side , when the response is done?
Looking for the solution which can not close the connection between client and the server with the Jersey REST API implementation?
Thanks & regards
Yatin Baraiya
as i have think to solve the my issue with the following approach.
Process implementation step to resolve the my issue
1.At First Sending request to the server ==========> Server immediately send the response to the client with generating some Id and start the long running process by other thread in the same process.
2.At the client side first it receive the first request response and wait for some seconds and then again send other request to the server for the long running process checking status====> Server get the second request and response to the client regarding the the status of the long running response status with sending in-progress or done
3.If client get the response :in-progress
4.Then client wait for some seconds and again send the request for status check ===> server Sending response to done
5.If client get the response :Done
then it start to take the other request from its queue . [ it will start the process for the next request if and only if client get the done status and generated ID]
it means here we manage the transaction from the client side with sending the multiple request to server and confirm the process is completed successfully or not , then we start to process next action.
With the above approach we got the transaction process ,Let me know is it my approach to solve the said issue , is it enough or any changes is required in this solution?
I have inherited an application (internal to my company) that uses javascript running in Internet Explorer which makes Ajax calls to a Struts-based application running in WebLogic Server v10.
Certain server-side operations in the system are taking longer than 3 minutes. Users consistently noticed that the Ajax call returns 503 error at the 3 minute mark. My users can wait longer than 3 minutes, but 503 errors interrupt their work.
This application needs to be performance tuned, but we badly need a temporary workaround to extend how much time can occur before a 503 error is returned.
The current theory is that the 503 error is being raised by the IE XMLHttpRequest object. A team of supposed WebLogic experts poured over our code and WebLogic logs, and declared that there's no timeout occurring on the server side. But I have my doubts.
My question is, which piece of software is responsible for raising 503 error: the browser, the Ajax javascript, or the server? And can this timeout period be changed?
A 503 error is kind of a catch-all for a lot of different types of errors, usually on the server side. In your case it could be that the server is just rejecting the connection after a certain timeout, and responding back with a 503 to indicate that the server is overloaded or cannot process your request.
A lot of times with web services, a 503 will be returned when the server code throws an exception or error. If the server code doesn't properly handle the error, it will bubble up to the server, which will just respond back with a generic 503.
http://www.checkupdown.com/status/E503.html
Error code 5xx (alternate definition)
RFC 2616
503 is a server error. XMLHttpRequest will happily wait longer than 3 minutes. The first thing you should do is satisfy yourself of that by visiting the problem URL in telnet or netcat or similar and seeing the 503 with javascript out of the picture.
Then you can proceed to find the timeout on the server side.
Your web server has a request reply timeout which is being tripped by long-running service requests. It could be the WebLogic server or a proxy. It is certainly not the client.
Have you considered submitting an asynchronous HTTP request that will be responded to immediately, and then polling another location for the eventual results? Three minutes is about 170 seconds too long.
503 is most likely due to a timeout on the server. If you can tune your Apache server, read about the Timeout attribute that you can set in httpd.conf.
Look in the httpd/logs/error_log to see if timeouts are occurring.
Refer also to this answer: Mod cluster proxy timeout in apache error logs .