Spring Boot Read timed out issue (SocketTimeoutException) - spring-boot

We have a Spring Boot app that at one point runs a Thread that calls a rest API and does something. When I run it on my machine it works well. Then if I run the same code on another machine it throws the error
SocketTimeoutException: Read timed out issue
So I thought there was some problem with server timeout. So on the other machine I've tried setting server.connection-timeout:-1 in the application.yml. since I've pulled the code from github, all the settings were identical. Then, after changing this on the other machine, it worked well there too.
So I am curious about the difference could be, maybe some settings on the machine itself? Where can I look?

Related

Unit tests for a OAuth/Config client Spring application

I have a very simple Spring application with cloud config client and oauth resources. It's turning out to be quite a challenge to run the unit tests without requiring the config server to be up.
None of the solutions out there for disabling cloud config client work for the latest version of spring. I have even tried to use empty or bogus config.import urls, but neither disable it. I really dont want to spin up the config server just for running unit tests and it doesnt feel like the correct way either.
What is the recommended way to setup tests for a config client application?
Looking for pointers, ideas.
Thankyou!
Making the configuration optional in test seems to do the job, though you still see an attempt being made to download the config.
spring.config.import: "optional:configserver:http://localhost:8888"
OR you can use
spring.cloud.config.enabled: false
However, client will always attempt to download the configuration, even though it appears to treat it as optional and moves on. I think this is really confusing for new users - one thinks the client is still enabled. What happens when the configserver is up and you expect the client to not download the config, but it still does. I guess the only way to find out is to test.
The weird part is that the following combination fails to load the context.
spring.config.import: "optional:configserver:http://localhost:8888"
spring.cloud.config.enabled: false
Either the import is set to optional or the config is disabled, but not both at the same time.
And, this is only for the tests. Creating another profile application-standalone.yml with same settings as test, fails.

Can a java TestContainer be started without attempting to call the default registry?

At work, we have decided we would like to use the java TestContainers package, and it has fallen to me to learn and implement this package. It is important to note that security is a top priority at work, so we are behind a proxy and run our own registry to contain our docker images.
This is what I've got so far.
var dockerImage = DockerImageName.parse("<secure-registry>/mongo:latest")
.asCompatibleSubstituteFor("mongo");
MongoDBContainer mongoDBContainer = new MongoDBContainer(dockerImage)
.withImagePullPolicy(PullPolicy.defaultPolicy())
.withExposedPorts(27019);
mongoDBContainer.start();
Not alot, but that's because I can't progress any further. Any time I attempt to run this code, it gets as far as .start() before throwing the following error
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 192.168.65.1:53: no such host"}
The issue is obviously that our proxy is blocking the default registry. I could probably fiddle with proxy settings on my machine so the registry can be resolved, but that is not a company wide solution. This app will be developed and run on many different machines and environments, and reconfiguring all of them would be more effort than it's worth. Furthermore, it shouldn't be communicating with the default registry at all. We have our own registry for a reason. The only real solution I see here is to remove this call entirely but so far, the documentation for both DockerImageName and the containers have been of no help.
If anyone has attempted this, or has another solution, it would be very helpful.
I have since realised my mistake. This page in the documentation reveals the problem. When running, the TestContainers library creates additional containers mainly for management of said containers. Unless a location is specified, it will attempt to pull these from the default registry. The preferred registry can be specified using the instructions in the link above.
As yuppie-flu also mentioned in their comment, this link may provide a nice, global way to set registries.

Spring Boot application not responding after pushing a large number of requests

I have a problem with a server that called server A:
Server A: Red Hat Enterprise Linux Server release 7.2 (Maipo)
Server B: Red Hat Enterprise Linux Server release 7.7 (Maipo)
jdk-8u231 installed on all of servers.
I have an Spring Boot application running on 2 servers.
Whenever i use Jmeter to send 100 concurrency request to application running on each servers, the application running on Server B have no problem.
But in Server A, the application will be not responding, that mean the Process (PID) still running but I can't visit actuator endpoint, cannot visit Swagger page, cannot send new request ... log file show nothing since that time.
Thread dump and heap dump have no significant difference.
Could anyone show me how to analysis that problem?
I still have no idea why the problem occur.
Well, I can only speculate here, but here some ideas that can help:
There are two possible sources of issue here Java Application and Linux (+its network policies, firewalls and so forth).
Since You don't know for sure, what happens, try working by "elimination".
Create a script that will run 100 concurrent requests. Place the script at the Server A (the problematic one) and run The script will run against "localhost" (obviously). If you see that it works, then the issue is not in Java at all. Probably some network policies or linux setup, who knows.
Place a log message in the controller of the java application and examine the log. The log should print the request number among other things, so that you'll be able to understand whether you get stuck after a well defined number of requests or its always a different number.
Check the configurations of Spring Boot application. Maybe there is a difference in the number of threads allocated to serve the request by the embedded web server that runs inside the spring boot application (assuming you're not using a reactive stack) and this number differs. In this case you won't be able to call rest endpoints, actuator, etc.
If JMX connection is available to the setup, connect via the JMX and check the MBean of Tomcat (again, assuming there is a tomcat under the hood) to check pretty much the same information as in 4.
You've mentioned thread dumps. Try to take more than one thread dump but one before you're running JMeter test, one during the running (when everything still works), one when everything is stuck.
In the thread dumps check the actual stacktraces, maybe all the threads are stuck working with Database or something and can't serve requests like I've explained in "4"
Examine GC logs, maybe GC works so hard that you can't really interact with the application.

Jetty webserver after idle breaks

I have a webapp deployed successfully in Jetty webserver.
The webserver responds to requests fine.
When I access the app it renders the home page.
Recently I noticed that when I don't use the app for certain period of time it breaks somehow. The period is somewhere around 2/3 weeks.
When I access the webapp after 2/3 weeks of idle I receive this output.
If I try to access any other link, i.e. the login page (/login.faces) I receive:
Problem accessing /error/not-found.faces. Reason:
/error/not-found.xhtml Not Found in ExternalContext as a Resource
which normally used to work before idling.
If I restart the webserver everything returns to normal and works fine. There are scheduled tasks set which make the app interact every day with database. (There is a scheduled task for fetching currency rates via webservice).
Therefore, my question is what would be the cause which breaks the site and makes it unavailable after idling? Is this a webserver (jetty) issue? Am I missing any setting which is crucial?
FYI, the project structure is: Java with Spring, Hibernate, JSF (PrimeFaces) and Jetty
This occurred due to permissions in CentOS.
If anyone faces the same issue make sure to check the logs have appropriate permissions to read and write

What can cause intermittent ORA-12519 (TNS: no appropriate handler found) errors

We are running our Junit 4 test suite against Weblogic 9 in front of an Oracle 10 database (using Hudson as a continuous integration server) and occasionally we will get an ORA-12519 crash during script teardown. However, the error is very intermittent:
It usually happens for the same Test class
It doesn't always happen for the same test cases (sometimes they pass)
It doesn't happen for the same number of test cases (anywhere from 3-9)
Sometimes it doesn't happen at all, everything passes
While I can't guarantee this doesn't happen locally (when running against the same database, of course), I have run the same suite of class multiple times with no issues.
Any ideas?
Don't know if this will be everybody's answer, but after some digging, here's what we came up with.
The error is obviously caused by the fact that the listener was not accepting connections, but why would we get that error when other tests could connect fine (we could also connect no problem through sqlplus)? The key to the issue wasn't that we couldn't connect, but that it was intermittent
After some investigation, we found that there was some static data created during the class setup that would keep open connections for the life of the test class, creating new ones as it went. Now, even though all of the resources were properly released when this class went out of scope (via a finally{} block, of course), there were some cases during the run when this class would swallow up all available connections (okay, bad practice alert - this was unit test code that connected directly rather than using a pool, so the same problem could not happen in production).
The fix was to not make that class static and run in the class setup, but instead use it in the per method setUp and tearDown methods.
So if you get this error in your own apps, slap a profiler on that bad boy and see if you might have a connection leak. Hope that helps.
Another solution I have found to a similar error but the same error message is to increase the number of service handlers found. (My instance of this error was caused by too many connections in the Weblogic Portal Connection pools.)
Run SQL*Plus and login as SYSTEM. You should know what password you’ve used during the installation of Oracle DB XE.
Run the command alter system set processes=150 scope=spfile; in SQL*Plus OR any SQL friendly IDE.
VERY IMPORTANT: Restart the database, to make the change effective in the SPFILE.
From here:
http://www.atpeaz.com/index.php/2010/fixing-the-ora-12519-tnsno-appropriate-service-handler-found-error/
I also had the same problem, I searched for the answers many places. I got many similar answers to change the number of process/service handlers. But I thought, what if I forgot to reset it back?
Then I tried using Thread.sleep() method after each of my connection.close();.
I don't know how, but it's working at least for me.
If any one wants to try it out and figure out how it's working then please go ahead. I would also like to know it as I am a beginner in programming world.
I had this problem in a unit test which opened a lot of connections to the DB via a connection pool and then "stopped" the connection pool (ManagedDataSource actually) to release the connections at the end of the each test. I always ran out of connections at some point in the suite of tests.
Added a Thread.sleep(500) in the teardown() of my tests and this resolved the issue. I think that what was happening was that the connection pool stop() releases the active connections in another thread so that if the main thread keeps running tests the cleanup thread(s) got so far behind that the Oracle server ran out of connections. Adding the sleep allows the background threads to release the pooled connections.
This is much less of an issue in the real world because the DB servers are much bigger and there is a healthy mix of operations (not just endless DB connect/disconnect operations).
I had the similar issue. It happened every time when I run a pack of database (Spring JDBC) tests with SpringJUnit4ClassRunner, so I resolved the issue putting #DirtiesContext annotation for each test in order to cleanup the application context and release all resources thus each test could run with a new initalization of the application context.

Resources