views:

7234

answers:

3

I'm using apache on one machine to serve requests to jboss on another machine. Everything works fine when I startup jboss and I'm able to access the web app, but after a few hours I eventually start getting "The proxy server received an invalid response from an upstream server" errors. If I restart jboss then everything works fine again, but several hours later I have the same issue...

Does anybody know what could be causing this issue? I don't have access to the apache logs at this time (I should in a few hours) but it seems to be something with jboss since restarting it is the temporary fix.

I'm using jboss4.2.3 and apache 1.3 with mod_jk. I'm not finding any errors in the jboss logs and the app I'm trying to reach isn't doing anything that takes a long time. The main page is just a simple login page. I have ports 8009 and 8080 open for communication between the app server and web server. I don't know what configuration is wrong.

+1  A: 

This sounds to me like mod_jk in Apache is getting out of sync with the AJP connector in JBoss. The AJP protocol uses persistent, re-used connections between web server and app server, and if the protocol is not configured exactly the same on both ends of the connection, eventually the connections go stale at one end of the connection, but the other end keeps trying to use them. The symptom is a 502 error.

My first suggestion is this: don't use mod_jk unless you need to. It's complex and hard to configure to get a stable system. If you don't need its performance or load balancing features, I suggest using mod_proxy instead. It's just as good for most applications, and pretty easy.

But if you want to stick to mod_jk, The first thing you need to is make sure you're using the very latest mod_jk version (currently 1.2.28), since older versions are notoriously hard to configure. Luckily, mod_jk is still supported on Apache 1.3.

Next, check the mod_jk log file (configured using the JkLogFile directive). If you're seeing a bunch of connection-related errors around the time things go wrong, you need to tweak your jk config at both ends of the connection. The most likely culprit is the timeout settings, so read up about those here, and make sure both ends are singing from the same hymn sheet.

skaffman
+1  A: 

I've also seen this occur using apache and tomcat. In my particular situation, the application deployed to tomcat had a bug that caused response threads to hang. Eventually tomcat ran out of worker threads, and apache wasn't able to establish a connection.

In our case, database connections weren't getting released properly back into a connection pool, and other threads were waiting indefinitely to obtain a connection from the pool. However, anything that indefinitely keeps alive a response handling thread could lead to the same problem.

dave
I rechecked the code and it doesn't seem that any threads are left open, but that's a good thing to keep in mind.I'm sure it's the issue with mod_jk that skaffman mentioned. I'm able to always access the site by using the address to the jboss machine, it's just when I'm trying to access it through apache that I get the error.
ravun
I tried editing some of the mod_jk configuration, but the issue persists. The config is very basic and I can't figure any reason why it would be causing an issue.After the site began timing out again I started checking the network traffic on the app server and it shows numerous "ESTABLISHED" connections on port 8009 and they aren't closing... even after 30 mins. So, it's looking like maybe it is the issue you shuggested.I checked my database connections and I'm closing the connections after using them, so I don't know what else could be causing the issue. Could it be something else?
ravun
A: 

I've been facing the same issue, in my scenario we have two servers which are handled by a loadbalancer, initially both functions well, but at times one of the server starts throwing 502 to some of the requests made, and gradually to all the requests. After one of the server is down, the other server faces all the load and as it could not handle all the load, even that goes down.

I have checked and double checked all the configurations of the mod_jk, still not able to figure it out why it has been throwing 502 Bad Gateway error to the user.

Could there be other reasons like network overload/congestion resulting into such issue.

Please suggest.

Daxesh