Tomcat 6.0.18 gets stuck after some while - tomcat6

After some while, Tomcat (6.0.18) gets stuck:
When I did netstat -an | grep 8080 everything seems stuck!
For example, recv-Q and send-Q remain with the same numbers.
and when I try to
run a simple Http client code:
URL u = new java.net.URL("http://localhost:8080/my/test")
c = u.openConnection();
c.getInputStream();
The client waits (until timeout) during getInputStream.
Any known issues with 6.0.18?
Any parameters I should check?
Thank you

You can fire up Visual VM and check out memory generations, especially perm gen, and threads. I'd try that. Be sure to install all the plugins for maximum information. Just start up Visual VM and attach it to the Tomcat PID.
A Google search of "Tomcat 6 hangs" brought back bunches:
http://www.tomcatexpert.com/ask-the-experts/tomcat-hang-after-a-random-period-of-time

Related

Substrate Blockchain - Create First Blockchain FrontEnd doesn´t open

I am on the first tutorial of Substrate, running substrate on Windows Subsystem for Linux. The substrate network is running correctly, but when I open the frontend on the browser i get this erros:
Because you run on the subsystem I would recommend you to check the network configuration for that. here is my be help :
Sharing Network Resources WSL
I have encountered and resolved this problem. WSL share the same ip with host, you known. you should make sure weather your wsl's ip is the same one that your frontend connect to. Generally, it is same one. I just closed the wls terminal console window and reopen it, it can be works! I don't know why, Perhaps, the bugs of wsl lead to it. Good Luck, guy!
From what I've experienced, getting Windows and WSL communicating through localhost is tricky and prone to falling over. I resolved the issue by making use of WSL's internal network IP address.
When you run the front-end server (yarn start) it shows you the internal network IP you can use to open the frontend. Or you can run
ip addr | grep -E "\b*inet.*global" | sed -E s/inet(.*)\/.*/\1/
(which I got from https://github.com/microsoft/WSL/issues/4636)
Next, you have to run the node-template with the --ws-external flag (in addition to the --dev and --tmp flags), so that it binds to 0.0.0.0 and allows you to connect to from windows.
Finally, you have to edit the src/config/development.json so that the PROVIDER_SOCKER variable uses the internal IP address and not 127.0.0.1.

Client Mongoose C app to query LAN DNS?

I'm experimenting with Cesanta's Mongoose server/"client" networking library in C. This is in Windows 7 x64 using Pelle's C. I'm trying to make a LAN-capable text messaging app on port 90 as two dialog-as-main executables (server and client) to support 20 connections to the server. FWIW, I'm using a fast timer to call mg_mgr_poll(&mgr, 0) which retains UI responsiveness and uses very little CPU.
Cesanta gives good examples of server communication setup and that works flawlessly. I can also get a client to connect to the server, but the server's IP address must be used in mg_connect().
Since the server's hostname is public to the LAN, I was hoping to ask the LAN for this host's IP. I had this working in VB awhile ago:
Dim host As New IPHostEntry
host = Dns.GetHostEntry(hostName)
Return host.AddressList.GetValue(0)
However as the VB project got bigger, VB got stranger and much more difficult, so I migrated to good old C. (Perhaps it was falling back to a NetBIOS name query, dunno.) No, I'd rather not migrate again to C# or C++/VS.
The Cesanta documentation on DNS resolution is quite vague. Code like mg_connect(&mgr, "MyServerPC:90", ev_handler); simply crashes, despite mg_connect stating it will try and resolve hostnames.
Can Mongoose resolve a local (LAN) hostname, and how? Or is this futile, and should everything be done manually in Winsock?
i have the same issue as you.
First i think that the mg_connect should not crashes, only if you try to do something with the returned connection which is null.
Second, mongoose try to resolve the address using DNS from specific location at the registry and it's take the first address he can find.
The location is :SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces
,check here in each of the interfaces.
i think there is a bug here (i am going to open an issues for it and also try to fix it and created a pull request).
Little update:
i have opend an issue and create a pull request about this issue.
https://github.com/cesanta/mongoose/issues/832
https://github.com/cesanta/mongoose/pull/833
Mongoose check each interface for the Value of NameServer and DhcpNameServer ,and return the first one (which is not empty) it can find but if it found an empty value for NameServer it doesn't check DhcpNameServer(and therefore miss the correct address) which will cause an error and direct the name resolving to a default server(i think it's google DNS -8.8.8.8).
You can fix this by going to the registry and adding the value of your DNS address to the registry key-NameServer
this is a comment from mongoose code:
/*
* See https://github.com/cesanta/mongoose/issues/176
* The value taken from the registry can be empty, a single
* IP address, or multiple IP addresses separated by comma.
* If it's empty, check the next interface.
* If it's multiple IP addresses, take the first one.
*/

remove one IP from linux route cache programatically

I made a back-end server which redirects users who abuse the main server (via too many invalid webpage requests in a short time) to another port so that the load on the server will be slightly less.
I then in my program via a exec() issue this command to block the IP from regular service:
iptables -t nat -I <tableforport> -p tcp --src <offending ip> -j REDIRECT --to-port <port of my server>
The problem is when I test this using an actual 2-computer setup where one is the client spamming the server (I'm actually holding F5 down for a few minutes to test), The internal port redirection doesn't seem to kick in right away. If I pause from holding F5 down for a few minutes then try again, then the internal redirection works and the blocking message from my server software works.
I feel this is due to linux (which the server runs on) caching remote IP address entries along with its ports along with other instructions causing the new iptables rules (like the one above) to be skipped until the routing cache is flushed for that IP.
In linux, I can easily flush the routing cache for each IP version via:
echo 1 > /proc/sys/net/ipvn/route/flush
where n in ipvn is either a 4 or 6.
The problem with that is if I execute it, then all the good IP's in cache will be flushed which in turn creates a slower experience for all. I only want to create a bad experience to potential hackers.
How do I go about removing only one IP address from the route cache so that when I add a redirection rule to iptables (like above), the redirection takes place right away the moment the client refreshes the page (not several refreshes, seconds or minutes later)?
Once I get an answer, I want to be able to make a C program out of it after which I can probably figure out myself.

Bind failed: Address already in use

I am attempting to bind a socket to a port below:
if( bind(socket_desc,(struct sockaddr *) &server, sizeof(server)) < 0)
{
perror("bind failed. Error");
return 1;
}
puts("bind done");
But it gives:
$ ./serve
Socket created
bind failed. Error: Address already in use
Why does this error occur?
Everyone is correct. However, if you're also busy testing your code your own application might still "own" the socket if it starts and stops relatively quickly. Try SO_REUSEADDR as a socket option:
What exactly does SO_REUSEADDR do?
This socket option tells the kernel that even if this port is busy (in
the TIME_WAIT state), go ahead and reuse it anyway. If it is busy,
but with another state, you will still get an address already in use
error. It is useful if your server has been shut down, and then
restarted right away while sockets are still active on its port. You
should be aware that if any unexpected data comes in, it may confuse
your server, but while this is possible, it is not likely.
It has been pointed out that "A socket is a 5 tuple (proto, local
addr, local port, remote addr, remote port). SO_REUSEADDR just says
that you can reuse local addresses. The 5 tuple still must be
unique!" by Michael Hunter (mphunter#qnx.com). This is true, and this
is why it is very unlikely that unexpected data will ever be seen by
your server. The danger is that such a 5 tuple is still floating
around on the net, and while it is bouncing around, a new connection
from the same client, on the same system, happens to get the same
remote port. This is explained by Richard Stevens in ``2.7 Please
explain the TIME_WAIT state.''.
You have a process that is already using that port. netstat -tulpn will enable one to find the process ID of that is using a particular port.
Address already in use means that the port you are trying to allocate for your current execution is already occupied/allocated to some other process.
If you are a developer and if you are working on an application which require lots of testing, you might have an instance of your same application running in background (may be you forgot to stop it properly)
So if you encounter this error, just see which application/process is using the port.
In linux try using netstat -tulpn. This command will list down a process list with all running processes.
Check if an application is using your port. If that application or process is another important one then you might want to use another port which is not used by any process/application.
Anyway you can stop the process which uses your port and let your application take it.
If you are in linux environment try,
Use netstat -tulpn to display the processes
kill <pid> This will terminate the process
If you are using windows,
Use netstat -a -o -n to check for the port usages
Use taskkill /F /PID <pid> to kill that process
The error usually means that the port you are trying to open is being already used by another application. Try using netstat to see which ports are open and then use an available port.
Also check if you are binding to the right ip address (I am assuming it would be localhost)
if address is already in use can you just want to kill whoso ever process is using the port, you can use
lsof -ti:PortNumberGoesHere | xargs kill -9
source and inspiration this.
PS: Could not use netstat because it not installed already.
As mentioned above the port is in use already.
This could be due to several reasons
some other application is already using it.
The port is in close_wait state when your program is waiting for the other end to close the program.refer (https://unix.stackexchange.com/questions/10106/orphaned-connections-in-close-wait-state).
The program might be in time_wait state. you can wait or use socket option SO_REUSEADDR as mentioned in another post.
Do netstat -a | grep <portno> to check the port state.
It also happens when you have not give enough permissions(read and write) to your sock file!
Just add expected permission to your sock contained folder and your sock file:
chmod ug+rw /path/to/your/
chmod ug+rw /path/to/your/file.sock
Then have fun!
I was also facing that problem, but I resolved it.
Make sure that both the programs for client-side and server-side are on different projects in your IDE, in my case NetBeans. Then assuming you're using localhost, I recommend you to implement both the programs as two different projects.
To terminate all node processes:
killall -9 node
First of check which port are listening,
netstat -tlpn
then select available port to conect,
sudo netstat -tlpn | grep ':port'
Fix it into also to your server and clients interfaces. Go Barrier tab -> change settings, -> port value type -> save/ok
Check both clients and server have similar port values
Then Reload.
Now it should be ok.
Check for running process pid:
pidof <process-name>
Kill processes:
sudo kill -9 process_id_1 process_id_2 process_id_3

How to get a more stable socket connection in Linux/C

I'm running a game website where users connect using an Adobe Flash client to a C server running on a Fedora Linux box.
Often users complain about disconnects. Usually they're "Connection reset by peer"-disconnects.
Is there any way to make the connection more stable or does it all depend on the route from the user host to my server?
One thing I tried is to make it more stable by sending PING in clear text every other minute to avoid timeout problems.
Anyone got more ideas?
You are not exhausting the number of socket/memory use/cpu that the server process is given on the server, are you?
Do check with ulimit.
Also, if possible try to trace the error message in the source code (when a RST packet is sent--), i.e. when a send() or accept() returns an error value. In such cases print a debug message into the logs; if you really fancy debugging it do a simulation of the server:
run it into debug mode on a separate machine (possibly a clone of the server)
simulate thousands of connection (or find a network harnessing program)
backtrace the call and/or sniff the connection
where are you running the server?
at home? at work? at a hosting facility?
this will make a very big difference.
Can you design your app to connect to two sockets on the server and then load balance or make it active/passive (or active/active)?
You can use SO_KEEPALIVE TCP socket option.

Resources